Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Powers of two
(version: 0)
If they should be written in an array or in the loop as we go
Comparing performance of:
mm vs oo vs compiled first only vs compiled both
Created:
9 years ago
by:
Guest
Jump to the latest result
Tests:
mm
var j = "MSKU947765"; var s = 0; var r = [1,2,4,8,16,32,64,128,256,512]; for (var e=0;e<4;e++) { var c = j.charCodeAt(e)-55; s+=(Math.floor(c/10.2)+c)*r[e]; }; for (var e=4;e<10;e++){ s+=(j.charCodeAt(e)-48)*r[e]; }; var d = s % 11 % 10; return d;
oo
var j = "MSKU947765"; var sum = 0; for (var i = 0; i < 10; i++) { var m = j.charCodeAt(i); if (i < 4) { m -= 55; m += parseInt(m / 11); } else { m -= 48; } sum += m * Math.pow(2, i); } var d = sum % 11; if (d === 10) d = 0; return d;
compiled first only
var j = "MSKU947765"; var s = 0; var r = [1,2,4,8,16,32,64,128,256,512]; var c = j.charCodeAt(0)-55; s+=(Math.floor(c/10.2)+c)*r[0]; var c = j.charCodeAt(1)-55; s+=(Math.floor(c/10.2)+c)*r[1]; var c = j.charCodeAt(2)-55; s+=(Math.floor(c/10.2)+c)*r[2]; var c = j.charCodeAt(3)-55; s+=(Math.floor(c/10.2)+c)*r[3]; for (var e=4;e<10;e++){ s+=(j.charCodeAt(e)-48)*r[e]; }; var d = s % 11 % 10; return d;
compiled both
var j = "MSKU947765"; var s = 0; var r = [1,2,4,8,16,32,64,128,256,512]; var c = j.charCodeAt(0)-55; s+=(Math.floor(c/10.2)+c)*r[0]; var c = j.charCodeAt(1)-55; s+=(Math.floor(c/10.2)+c)*r[1]; var c = j.charCodeAt(2)-55; s+=(Math.floor(c/10.2)+c)*r[2]; var c = j.charCodeAt(3)-55; s+=(Math.floor(c/10.2)+c)*r[3]; s+=(j.charCodeAt(4)-48)*r[4]; s+=(j.charCodeAt(5)-48)*r[5]; s+=(j.charCodeAt(6)-48)*r[6]; s+=(j.charCodeAt(7)-48)*r[7]; s+=(j.charCodeAt(8)-48)*r[8]; s+=(j.charCodeAt(9)-48)*r[9]; var d = s % 11 % 10; return d;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
mm
oo
compiled first only
compiled both
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):
The provided benchmark is designed to measure the performance difference between two approaches: compiling the loop and executing it immediately, versus compiling the loop once and then reusing the compiled version. **Options being compared:** 1. **Compiled first only**: The loop is compiled beforehand and then executed repeatedly in a loop. This approach relies on a JavaScript compiler or transpiler like UglifyJS to convert the code into machine code. 2. **Compiled both**: Similar to "compiled first only", but the compiled version is stored in memory and reused multiple times, reducing the overhead of repeated compilations. **Pros and Cons:** 1. **Compiled first only**: * Pros: Reduces compilation time since it's done once upfront. * Cons: Increases memory usage as the compiled code needs to be stored in memory for each execution. 2. **Compiled both**: * Pros: Minimizes memory usage by reusing the compiled version, and reduces compilation overhead. * Cons: Requires more complex implementation, such as caching or storing the compiled code. **Other considerations:** * The use of `charCodeAt()` function suggests that this benchmark is testing the performance of character encoding and decoding operations in JavaScript. * The presence of the `Math.pow()` function implies that this benchmark also tests the performance of exponentiation operations. * The fact that the same input string is used for all test cases (`"MSKU947765"`), and that each test case has a unique variation, suggests that the benchmark is designed to isolate the effect of different loop execution strategies. **Library usage:** There is no explicit library mentioned in the provided code or benchmark definitions. However, it's worth noting that some JavaScript engines, like SpiderMonkey (used by Firefox), have built-in optimizations and caching mechanisms that can affect the performance of compiled loops. **Special JS feature/syntax:** None are explicitly mentioned in this benchmark. **Alternatives:** To measure loop execution performance in JavaScript, other alternatives include: * Using a profiling tool like Chrome DevTools or Node.js Inspector to profile the code. * Creating a custom benchmarking library using a framework like Benchmark.js. * Writing a test harness that iterates over a range of inputs and measures the execution time of each test case. Keep in mind that these alternatives might not provide the same level of control and customization as creating a bespoke benchmark like this one.
Related benchmarks:
Powers of two
Powers of two
pow vs multiply v2
Math.pow(2,n) vs Table lookup vs bitwise
Math.pow vs multiplication with decimals and multiple integers
Comments
Confirm delete:
Do you really want to delete benchmark?