Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sma - reduce - doc - new
(version: 0)
Comparing performance of:
reduce vs doc vs sma
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const close = [ 2.212, 2.211, 2.22, 2.21, 2.222, 2.219, 2.22, 2.225, 2.231, 2.224, 2.222, 2.218, 2.217, 2.201, 2.197, 2.2, 2.21, 2.202, 2.204, 2.202, 2.199, 2.2, 2.197, 2.198, 2.197, 2.196, 2.194, 2.193, 2.188, 2.189, 2.191, 2.193, 2.177, 2.179, 2.181, 2.18, 2.184, 2.176, 2.177, 2.169, 2.171, 2.168, 2.171, 2.171, 2.165, 2.17, 2.17, 2.17, 2.171, 2.174, 2.169, 2.167, 2.161, 2.16, 2.159, 2.161, 2.157, 2.154, 2.153, 2.152, 2.153, 2.156, 2.153, 2.149, 2.144, 2.146, 2.145, 2.146, 2.144, 2.137, 2.133, 2.131, 2.122, 2.126, 2.123, 2.124, 2.116, ] function sma_REDUCE_VERSION(source, length) { let sma = source.map((value, index, array) => { if (index < length) { value = NaN } else { value = array.slice(index - length, index) value = average(value) } return value }) return sma } function sma_DOC(source, window) { let result = [] if (source.length < window) { return result } let sum = 0 for (let index = 0; index < window; ++index) { sum += source[index] } result.push(sum / window) let steps = source.length - window - 1 for (let index = 0; index < steps; ++index) { sum -= source[index] sum += source[index + window] result.push(sum / window) } return result } function sma(source, period) { let size = source.length - 1 let output = [] let scale = 1.0 / period if (period < 1) return "Invalid Options" if (size <= period - 1) return "Out of range" let sum = 0 for (let index = 0; index < period; ++index) { sum += source[index] } // output.push(sum * scale) output[output.length] = sum * scale for (let index = period; index < size; ++index) { sum += source[index] sum -= source[index - period] // output.push(sum * scale) output[output.length] = sum * scale } return output }
Tests:
reduce
sma_REDUCE_VERSION(close, 10)
doc
sma_DOC(close, 10)
sma
sma(close, 10)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
reduce
doc
sma
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark definition and explain what's being tested, compared options, pros and cons of those approaches, and other considerations. **Benchmark Definition** The benchmark is measuring the performance of three different functions: `sma_REDUCE_VERSION`, `sma_DOC`, and `sma`. These functions are used to calculate a moving average (or exponential moving average) over a specified window size. **Test Cases** There are three test cases: 1. `reduce`: This test case uses the `sma_REDUCE_VERSION` function, which calculates the reduced version of the input array. 2. `doc`: This test case uses the `sma_DOC` function, which calculates the document (or "moving average") version of the input array. 3. `sma`: This test case uses the `sma` function, which is similar to `sma_DOC`, but with a slight difference in implementation. **Functions and Libraries** The three functions use the following libraries: 1. None 2. None (assuming it's a custom library for calculating moving averages) 3. Same as above These libraries are not explicitly mentioned in the benchmark definition, so I'll assume they're part of the benchmark framework or a custom implementation. **Options Compared** The three test cases compare different options for calculating moving averages: 1. `sma_REDUCE_VERSION`: This function reduces the input array to the specified window size and then calculates the average. 2. `sma_DOC`: This function calculates the document version of the input array, which is similar to a moving average, but with some differences in implementation. 3. `sma`: This function is similar to `sma_DOC`, but with a slight difference in implementation. **Pros and Cons** Here are some pros and cons of each option: 1. `sma_REDUCE_VERSION`: * Pros: Simple and efficient implementation. * Cons: May not be accurate for all cases, as it reduces the input array to the specified window size. 2. `sma_DOC`: * Pros: More accurate than `sma_REDUCE_VERSION`, as it calculates the average over a sliding window. * Cons: More complex implementation, which may introduce overhead. 3. `sma`: * Pros: Similar accuracy to `sma_DOC`, but with a simpler implementation. * Cons: Slight differences in implementation compared to `smaDOC`, which may affect accuracy. **Other Considerations** 1. Window size: The benchmark definition specifies a window size of 10, but it's not clear if this is the optimal value for all cases. 2. Performance: The benchmark results show that the `sma` function performs slightly better than `sma_DOC`, which may be due to its simpler implementation. 3. Accuracy: The accuracy of each option depends on the specific use case and requirements. In summary, the benchmark tests three different functions for calculating moving averages, comparing their pros and cons, and providing insights into their performance and accuracy.
Related benchmarks:
spread vs concat2
Spread v concat
index vs reduce
sma - doc or new
Comments
Confirm delete:
Do you really want to delete benchmark?