Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
parenthesis or not
(version: 0)
Comparing performance of:
parenthesis vs without vs 3 vs 4 vs 5
Created:
8 years ago
by:
Guest
Jump to the latest result
Tests:
parenthesis
var j = "MSKU765112"; var s = 0; var c1 = j.charCodeAt(0)-55; var c2 = j.charCodeAt(1)-55; var c3 = j.charCodeAt(2)-55; var c4 = j.charCodeAt(3)-55; s+=(Math.floor(c1/10.2)+c1)*1; s+=(Math.floor(c2/10.2)+c2)*2; s+=(Math.floor(c3/10.2)+c3)*4; s+=(Math.floor(c4/10.2)+c4)*8; s+=j.charCodeAt(4)*16-768; s+=j.charCodeAt(5)*32-1536; s+=j.charCodeAt(6)*64-3072; s+=j.charCodeAt(7)*128-6144; s+=j.charCodeAt(8)*256-12288; s+=j.charCodeAt(9)*512-24576; var d = s % 11 % 10; return d;
without
var j = "MSKU765112"; 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)*16-768; s+=j.charCodeAt(5)*32-1536; s+=j.charCodeAt(6)*64-3072; s+=j.charCodeAt(7)*128-6144; s+=j.charCodeAt(8)*256-12288; s+=j.charCodeAt(9)*512-24576; var d = s % 11 % 10; return d;
3
var j = "MSKU765112"; 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;
4
var j = "MSKU765112"; var d = (((Math.floor((j.charCodeAt(0)-55)/10.2)+(j.charCodeAt(0)-55))*1)+((Math.floor((j.charCodeAt(1)-55)/10.2)+(j.charCodeAt(1)-55))*2)+((Math.floor((j.charCodeAt(2)-55)/10.2)+(j.charCodeAt(2)-55))*4)+((Math.floor((j.charCodeAt(3)-55)/10.2)+(j.charCodeAt(3)-55))*8)+(j.charCodeAt(4)*16-768)+(j.charCodeAt(5)*32-1536)+(j.charCodeAt(6)*64-3072)+(j.charCodeAt(7)*128-6144)+(j.charCodeAt(8)*256-12288)+(j.charCodeAt(9)*512-24576)) % 11 % 10; return d;
5
var o = "MSKU765112"; var a=0,n=-55,e=-48; var x=n+o.charCodeAt(0); var z=n+o.charCodeAt(1); var w=n+o.charCodeAt(2); var v=n+o.charCodeAt(3); a+=x+((x<<7)-(x<<5)+(x<<2)>>10)>>0; a+=z+((z<<7)-(z<<5)+(z<<2)>>10)>>0<<1; a+=w+((w<<7)-(w<<5)+(w<<2)>>10)>>0<<2; a+=v+((v<<7)-(v<<5)+(v<<2)>>10)>>0<<3; a+=e+o.charCodeAt(4)<<4; a+=e+o.charCodeAt(5)<<5; a+=e+o.charCodeAt(6)<<6; a+=e+o.charCodeAt(7)<<7; a+=e+o.charCodeAt(8)<<8; a+=e+o.charCodeAt(9)<<9; var d=a%11%10; return d;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
parenthesis
without
3
4
5
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 the benchmark and explain what is being tested. The provided JSON represents a set of JavaScript microbenchmarks created using the MeasureThat.net website. The benchmarks test different approaches to calculating a specific result, which appears to be related to string manipulation and arithmetic operations. **Benchmark Structure** Each test case consists of two parts: 1. **Script Preparation Code**: This section contains the code that sets up the input data for the benchmark. 2. **Benchmark Definition**: This section defines the mathematical operation or logic that needs to be executed. The code is written in JavaScript, and it performs various arithmetic operations using bitwise shifts and additions. **Test Cases** There are five test cases, labeled as "5", "4", "3", "without", and "parenthesis". Each case has a unique way of performing the calculation: * **Case 5**: Uses a simple loop to perform the calculation. * **Case 4**: Similar to Case 5, but with some minor differences in the arithmetic operations. * **Case 3**: Uses a combination of bitwise shifts and additions to perform the calculation. * **Without Parentheses**: Removes the parentheses from the mathematical expression, making it more challenging to calculate. * **Parenthesis**: Keeps the original code with parentheses, which may provide better performance due to reduced overhead. **Browser Results** The latest benchmark results show that different browsers (in this case, Firefox 54) execute each test case at varying rates. The results are based on the number of executions per second (`ExecutionsPerSecond`). **Key Takeaways** * Case 5 and Case 4 seem to perform similarly, suggesting that minor differences in arithmetic operations have minimal impact on performance. * Case 3's use of bitwise shifts may provide a slight performance boost compared to Cases 5 and 4. * Removing parentheses (Case "without") seems to incur a significant performance penalty. * Keeping the original code with parentheses (Case "parenthesis") appears to result in the best performance, likely due to reduced overhead from parsing and evaluating expressions. Overall, these results suggest that the choice of implementation can significantly impact performance, even for simple arithmetic operations.
Related benchmarks:
IIFE vs Normal Fixed
IIFE vs Normal Fixed 2
jQuery parents() vs closest()
parentElement vs parentNode
parentElement vs parentNode (multiple)
Comments
Confirm delete:
Do you really want to delete benchmark?