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 vs compiled both with compiled powers
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;
compiled both with compiled powers
var j = "MSKU947765"; var s = 0; var c = j.charCodeAt(0)-55; s+=(Math.floor(c/10.2)+c)*1; var c = j.charCodeAt(1)-55; s+=(Math.floor(c/10.2)+c)*2; var c = j.charCodeAt(2)-55; s+=(Math.floor(c/10.2)+c)*4; var c = j.charCodeAt(3)-55; s+=(Math.floor(c/10.2)+c)*8; s+=(j.charCodeAt(4)-48)*16; s+=(j.charCodeAt(5)-48)*32; s+=(j.charCodeAt(6)-48)*64; s+=(j.charCodeAt(7)-48)*128; s+=(j.charCodeAt(8)-48)*256; s+=(j.charCodeAt(9)-48)*512; var d = s % 11 % 10; return d;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
mm
oo
compiled first only
compiled both
compiled both with compiled powers
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):
Let's dive into explaining the benchmark. **Benchmark Definition** The benchmark is designed to measure the performance of JavaScript code that calculates the last digit of a number represented as a base-11 integer, where the digits are encoded in ASCII characters. **Options Compared** There are four options being compared: 1. **`compiled first only`**: This option compiles the powers of two calculation separately before iterating over the remaining digits. 2. **`mm`**: This option iterates over the first 4 digits and then iterates over the remaining 6 digits without compiling the powers of two calculation. 3. **`oo`**: This option iterates over all 10 digits, but compiles only the powers of two calculation separately from the iteration. 4. **`compiled both`** and **`compiled both with compiled powers`**: These options compile both the iteration and the powers of two calculation, either together or separately, respectively. **Pros and Cons** Here's a brief summary of each option: * **`compiled first only`**: + Pros: May have better cache locality due to contiguous memory access. + Cons: Requires more memory accesses during the initial compilation step. * **`mm`**: + Pros: Simple and easy to implement. + Cons: May result in less efficient iteration over the remaining digits. * **`oo`**: + Pros: Compiles powers of two calculation separately, which can improve performance for large inputs. + Cons: Requires more memory accesses due to separate compilation. * **`compiled both`** and **`compiled both with compiled powers`**: + Pros: Can potentially reduce the number of iterations required, as both the iteration and powers of two calculation are optimized together. + Cons: May require more complex code and additional memory accesses during the initial compilation step. **Latest Benchmark Results** The latest benchmark results show that **`compiled both with compiled powers`** outperforms all other options, followed closely by **`compiled both`**. The remaining options result in lower execution rates. It's worth noting that these results may depend on various factors such as the input size, JavaScript engine, and hardware configuration.
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?