Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
fast square roo
(version: 1)
Comparing performance of:
the middle vs fisqrt
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var i; var r; var v = 2**16; function test1() { for(i=0; i < 1000; ++i) { r = getTheMiddle(v); } } function test2() { for(i=0; i < 1000; ++i) { r = Q_rsqrt(v) * v; } } function getTheMiddle(number){ var start = 0; var end = number; var theMiddle = (start+end)/2; while (Math.abs(theMiddle*theMiddle - number) > 0.00001) { if (theMiddle*theMiddle > number) { end = theMiddle; } else { start = theMiddle; } theMiddle = (start+end)/2; return theMiddle; } } //Based on the fast inverse square root function // https://en.wikipedia.org/wiki/Fast_inverse_square_root // Some original comments preserved for humor value // Designed to try to mimic the original as closely as possible function Q_rsqrt(number) { var i; var x2, y; const threehalfs = 1.5; x2 = number * 0.5; y = number; //evil floating bit level hacking var buf = new ArrayBuffer(4); (new Float32Array(buf))[0] = number; i = (new Uint32Array(buf))[0]; i = (0x5f3759df - (i >> 1)); //What the fuck? (new Uint32Array(buf))[0] = i; y = (new Float32Array(buf))[0]; y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed return y; }
Tests:
the middle
test1();
fisqrt
test2();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
the middle
fisqrt
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'd be happy to explain what's being tested on the provided JSON. **Benchmark Test** The benchmark test is designed to measure the performance of two different approaches for calculating the middle value of a large number. The benchmark is named "fast square root" and consists of two individual test cases: "the middle" and "fisqrt". **Approaches Compared** The two approaches being compared are: 1. **Manual implementation**: This approach uses a custom function `getTheMiddle` to calculate the middle value. The function iteratively updates its bounds until it finds the exact middle value. 2. **Fast inverse square root (FISRT) library**: This approach uses a pre-written library function `Q_rsqrt` to calculate the inverse square root of a number. **Pros and Cons** **Manual implementation:** Pros: * Control over the implementation * Can be optimized for specific use cases Cons: * More complex code * May not be as efficient as specialized libraries **FISRT library:** Pros: * Highly optimized for performance * Provides a reliable and accurate result Cons: * Requires an external library (which may have dependencies) * Limited control over the implementation **Other Considerations** The benchmark also takes into account the device platform, operating system, and browser version used to run the test. This helps to isolate any platform or browser-specific issues. **Library: FISRT Library** The `Q_rsqrt` function in the benchmark is an implementation of the fast inverse square root algorithm from Wikipedia. The library provides a pre-written function for calculating the inverse square root, which is optimized for performance. **Special JS Features** There are no special JavaScript features or syntax used in this benchmark that require explanation. **Alternatives** If you want to run similar benchmarks, here are some alternatives: 1. **Benchmark.js**: A popular benchmarking library for JavaScript. 2. **Benchmark suite**: A set of benchmarking tools for JavaScript and other languages. 3. **Google Benchmark**: A high-performance benchmarking framework for C++ and other languages (with a JavaScript wrapper available). Keep in mind that the specific alternatives will depend on your needs and goals, but these options are widely used and well-regarded in the industry.
Related benchmarks:
Fast Sqrt
Fast Sqrt 2
Fast Sqrt 2234234
Inv Fast Sqrt
Fast Sqrt0
Comments
Confirm delete:
Do you really want to delete benchmark?