Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Fast Sqrt 2234234
(version: 0)
Compare Quakes fast inverse squareroot
Comparing performance of:
Math.sqrt vs Quakes fast inverse sqrt.
Created:
5 years ago
by:
Guest
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 = 1 / Math.sqrt(v); } } function test2() { for(i=0; i < 1000; ++i) { r = Q_rsqrt(v); } } //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:
Math.sqrt
test1();
Quakes fast inverse sqrt.
test2();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Math.sqrt
Quakes fast inverse sqrt.
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 world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Definition** The provided JSON represents a benchmark definition for a JavaScript function called `Fast Sqrt 2234234`. This function is designed to compare two implementations of fast inverse square root calculations, specifically: 1. The built-in `Math.sqrt` method. 2. A custom implementation named "Quakes fast inverse sqrt." (also referred to as `Q_rsqrt`). The benchmark measures the performance difference between these two approaches. **Options Compared** The main options being compared are: * **Built-in Math.sqrt**: This is the standard JavaScript method for calculating square roots. * **Quakes fast inverse sqrt. (Q_rsqrt)**: A custom implementation of fast inverse square root, which is designed to mimic the original algorithm from Wikipedia. **Pros and Cons** Here's a brief analysis of each approach: 1. **Built-in Math.sqrt**: * Pros: + Wide support across browsers and platforms. + Easy to use and understand. * Cons: + May not be optimized for performance, leading to slower execution times. 2. **Quakes fast inverse sqrt. (Q_rsqrt)**: * Pros: + Optimized for performance, potentially reducing execution times. + Can provide a more accurate result than the built-in method. * Cons: + Requires manual implementation and understanding of the algorithm. + May not be compatible with all browsers or platforms. **Library: Quakes** The `Q_rsqrt` function is implemented in JavaScript, but it relies on some mathematical tricks and bit-level manipulation. The library used for this implementation is not explicitly stated, but it's likely a custom-built library optimized for performance. **Special JS Feature/Syntax** This benchmark uses some special JavaScript features, such as: * Bit-level manipulation (e.g., `0x5f3759df - (i >> 1)`). * Floating-point arithmetic (e.g., `(new Float32Array(buf))[0] = number;`). These features are specific to the implementation and may not be widely supported or understood. **Other Alternatives** If you're interested in exploring other approaches, here are a few alternatives: * **SSE instructions**: Some implementations use SSE (Streaming SIMD Extensions) instructions for optimized performance on x86 architectures. * **AVX instructions**: Similar to SSE, AVX (Advanced Vector Extensions) instructions can be used for even faster performance on modern CPUs. * **Native libraries**: You can also consider using native libraries like Eigen or Armadillo for more efficient linear algebra operations. Keep in mind that implementing these alternatives will require a good understanding of low-level computer science and programming expertise. I hope this explanation helps you understand the basics of the JavaScript microbenchmark on MeasureThat.net!
Related benchmarks:
Fast Sqrt
Fast Sqrt 2
Inv Fast Sqrt
Fast Sqrt0
Comments
Confirm delete:
Do you really want to delete benchmark?