Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sma - doc or new
(version: 0)
Comparing performance of:
doc vs new
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_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:
doc
sma_DOC(close, 10)
new
sma(close, 10)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
doc
new
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 definitions and explain what's being tested. **Benchmark Definitions** The two benchmark definitions are: 1. `sma_DOC(source, window)`: This function calculates the Simple Moving Average (SMA) of an input array `source` with a specified `window` size. 2. `sma(source, period)`: This function also calculates the SMA, but it uses a fixed `period` instead of a variable `window`. **Options Being Compared** The two options being compared are: * Using the `DOC` method (`sma_DOC`) vs. using the `NEW` method (`sma`). * Using a fixed `window` size in the `DOC` method vs. using a fixed `period` size in the `NEW` method. **Pros and Cons** 1. **Using the DOC method:** * Pros: + May be faster due to fewer calculations required. + Can provide more accurate results for smaller window sizes. * Cons: + May not work well for larger window sizes or datasets with many unique values. + Can lead to rounding errors if the window size is not a divisor of the dataset length. 2. **Using the NEW method:** * Pros: + Works well for larger window sizes and datasets with many unique values. + Reduces rounding errors by using a fixed `period` size. * Cons: + May be slower due to additional calculations required. + Can lead to increased memory usage. **Library:** The library being used in the benchmark is not explicitly mentioned. However, based on the function names and syntax, it appears to be a JavaScript implementation of a Simple Moving Average (SMA) calculator. **Special JS Feature/Syntax:** There are no special JavaScript features or syntaxes mentioned in the provided code snippets. **Other Considerations:** * The `sma_DOC` method uses a simple iterative approach, while the `sma` method uses a more optimized approach with fixed window size calculations. * The benchmark results show that the `NEW` method performs slightly better than the `DOC` method on the test cases provided. **Alternatives:** Other alternatives for calculating Simple Moving Average (SMA) include: 1. Using a built-in JavaScript function, such as `Array.prototype.reduce()`, to calculate the SMA. 2. Using a library like Lodash or Moment.js, which provide optimized implementation of SMA calculation. 3. Implementing a more advanced algorithm, such as an Exponential Smoothing (ES) method, for improved accuracy and stability. Keep in mind that these alternatives may have different trade-offs in terms of performance, memory usage, and accuracy, depending on the specific use case and requirements.
Related benchmarks:
spread vs concat2
index vs reduce
sma - reduce - doc - new
Array.concat vs Spread Operator in 100 numberv33
Comments
Confirm delete:
Do you really want to delete benchmark?