Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
а я думал создание итератора будет дороже
(version: 0)
Comparing performance of:
smi vs deopt to heapnumber vs iterator
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
smi
function add(a,b) { return a + b; } var arr = Array.from({length: 10000}, (_, i) => ([i, i+1])) var xs = arr.map(pair => add(pair[0], pair[1]))
deopt to heapnumber
function add(a,b) { return a + b; } var arr = Array.from({length: 10000}, (_, i) => Math.random() > 0.95 ? ([i, i+1]) : ([i, i+1.1])) var xs = arr.map(pair => add(pair[0], pair[1]))
iterator
function add(a,b) { return a + b; } var arr = Array.from({length: 10000}, (_, i) => ([i, i+1])) var xs = arr.map(([a,b]) => add(a, b))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
smi
deopt to heapnumber
iterator
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Browser/OS:
Chrome 116 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
smi
2937.2 Ops/sec
deopt to heapnumber
926.5 Ops/sec
iterator
2843.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring the performance of JavaScript microbenchmarks is an interesting task. **Benchmark Definition** The provided JSON represents a benchmark definition, which includes: * `Script Preparation Code`: The code used to prepare and set up the test case. In this case, it's empty, so no preparation code is executed. * `Html Preparation Code`: The HTML code used to prepare and render the webpage for the test. Again, it's empty. * `Name` and `Description`: Human-readable names and descriptions of the benchmark. The actual benchmarking part is implemented in the `Benchmark Definition` strings for each individual test case. **Individual Test Cases** Each test case measures the performance of a different JavaScript approach to perform an addition operation on arrays: 1. **"smi"`**: This test case uses traditional array indexing (`arr.map(pair => add(pair[0], pair[1]))`) and is likely testing the performance of this common use case. * Pros: Easy to understand, widely used. * Cons: May not be optimized for performance in certain browsers or architectures. 2. **"deopt to heapnumber"`**: This test case uses a technique called "deoptimization" to detect when an operation should be performed on a heap (managed memory) instead of the stack (unmanaged memory). In this case, it's used with floating-point numbers (`Math.random() > 0.95 ? ([i, i+1]) : ([i, i+1.1])`). * Pros: Can improve performance in certain cases by reducing allocation and deallocation overhead. * Cons: May introduce additional complexity and potential bugs. 3. **"iterator"`**: This test case uses an iterator (`arr.map(([a,b]) => add(a, b))`) to perform the addition operation. Iterators are a more modern way of iterating over arrays in JavaScript. * Pros: Can be more memory-efficient and provide better performance in certain cases. * Cons: May require additional browser support and configuration. **Library and Special JS Features** There is no explicitly mentioned library used in these benchmark definitions. However, the use of `Array.from()` suggests that modern JavaScript engines are being tested. The only special feature that stands out is the "deoptimization" technique used in the second test case (`"deopt to heapnumber"`). This is a complex optimization technique that requires careful consideration and testing to ensure correct behavior and performance. **Other Alternatives** Other alternatives for performing addition operations on arrays might include: * Using `reduce()` instead of `map()` * Using a custom loop with array indexing * Utilizing SIMD (Single Instruction, Multiple Data) instructions if available in the target browser Keep in mind that these alternatives may not be relevant to the specific benchmark or use case. **Conclusion** The provided benchmark definitions test different approaches to performing addition operations on arrays. The "smi" test case uses traditional array indexing, while the "deopt to heapnumber" test case leverages deoptimization for floating-point numbers. The "iterator" test case demonstrates the use of iterators for array iteration. Understanding these differences and their implications can help developers optimize their JavaScript code for better performance.
Related benchmarks:
ruse compiler factorial 001
ruse compiler factorial 002
ruse compiler factorial 003
ruse compiler factorial 004
ruse compiler factorial 010
Comments
Confirm delete:
Do you really want to delete benchmark?