Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Compare GCD_
(version: 0)
Compare GCD
Comparing performance of:
Bottom Up vs Top Down vs Good non-recursion vs Good Recusion
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function gcd(a, b){ var divisor = 2, greatestDivisor = 1; if (a < 2 || b < 2) return 1; while(a >= divisor && b >= divisor){ if(a %divisor == 0 && b% divisor ==0){ greatestDivisor = divisor; } divisor++; } return greatestDivisor; } function gcd1(a,b){ var divisor = a < b ? a : b; if(a < 2 || b < 2){ return 1; } while(divisor > 0){ if(a % divisor === 0 && b % divisor === 0){ return divisor; } divisor--; } } function gcd2(a, b){ var x; while(b !== 0){ x = a % b; a = b; b = x; } return a; } function gcd3(a, b){ if(b === 0) return a; return gcd3(b, a % b); }
Tests:
Bottom Up
gcd(27, 12);
Top Down
gcd1(27, 12);
Good non-recursion
gcd2(27, 12);
Good Recusion
gcd3(27, 12);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Bottom Up
Top Down
Good non-recursion
Good Recusion
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 provide an explanation of the benchmark and its various components. **Benchmark Definition** The provided JSON represents a JavaScript microbenchmark test case named "Compare GCD". The benchmark aims to compare the execution performance of four different implementations of the Greatest Common Divisor (GCD) algorithm: `gcd`, `gcd1`, `gcd2`, and `gcd3`. **Script Preparation Code** The script preparation code provides the implementation details for each GCD algorithm: * `gcd(a, b)`: This is a simple iterative approach that uses a while loop to find the greatest common divisor. * `gcd1(a,b)`: This is a top-down recursive approach that first finds the maximum of `a` and `b`, then iteratively checks for divisibility. * `gcd2(a, b)`: This algorithm uses the Euclidean algorithm with a twist. It repeatedly applies the modulo operation to find the GCD without using recursion. * `gcd3(a, b)`: This is another recursive approach that uses function calls to recursively calculate the GCD. **Html Preparation Code** The `Html Preparation Code` field is empty in this case, indicating that no HTML code is required for the benchmark. **Individual Test Cases** The provided JSON contains four test cases, each representing a different implementation of the GCD algorithm: * `Bottom Up`: This test case uses the `gcd(a, b)` function. * `Top Down`: This test case uses the `gcd1(a,b)` function. * `Good non-recursion`: This test case uses the `gcd2(a, b)` function, which is considered a good approach as it avoids recursion and is more efficient. * `Good Recursion`: This test case uses the `gcd3(a, b)` function, which is another recursive approach. **Benchmark Results** The latest benchmark results show the execution performance of each test case on a Chrome 101 browser running on Linux. The `ExecutionsPerSecond` field provides the number of executions per second for each test case: * `Good non-recursion`: 8205014.5 * `Top Down`: 6678458.0 * `Bottom Up`: 6485160.0 * `Good Recursion`: 2823265.5 **Library and Special Features** None of the provided test cases use any external libraries, but they do utilize JavaScript features like recursion (`gcd1`, `gcd3`) or iterative approaches with a twist (`gcd2`). **Alternatives** For those interested in exploring alternative GCD algorithms or improving upon these implementations, some options include: * Using a more efficient algorithm like the Binary GCD algorithm. * Implementing a hybrid approach combining elements of different methods (e.g., using recursion for smaller inputs and iteration for larger ones). * Leveraging libraries or frameworks that provide optimized GCD functions. These alternatives might offer improved performance, readability, or maintainability, depending on the specific use case.
Related benchmarks:
Compare GCD
Compare GCD
Compare GCD
Compare GCD
Comments
Confirm delete:
Do you really want to delete benchmark?