Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Quake InvertSqrt
(version: 0)
Comparing performance of:
Math.sqrt vs Quake InvertSqrt
Created:
7 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 = Math.sqrt(v); } } function test2() { for(i=0; i < 1000; ++i) { r = Q_rsqrt(v) * v; } } const bytes = new ArrayBuffer(Float32Array.BYTES_PER_ELEMENT); const floatView = new Float32Array(bytes); const intView = new Uint32Array(bytes); const threehalfs = 1.5; function Q_rsqrt(number) { const x2 = number * 0.5; floatView[0] = number; intView[0] = 0x5f3759df - ( intView[0] >> 1 ); let y = floatView[0]; y = y * ( threehalfs - ( x2 * y * y ) ); return y; }
Tests:
Math.sqrt
test1()
Quake InvertSqrt
test2()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Math.sqrt
Quake InvertSqrt
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0
Browser/OS:
Chrome 133 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Math.sqrt
677609.2 Ops/sec
Quake InvertSqrt
53540.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **Benchmark Definition** The benchmark definition json contains two test cases: 1. `test1()`: This function calls `Math.sqrt(v)` 1000 times, where `v` is initialized to a power of 2 (2^16). 2. `test2()`: This function calls the custom `Q_rsqrt` function, which is an implementation of the Quake Invert Sqrt algorithm. The input `number` is also initialized to a power of 2 (2^16). **Options being compared** The two test cases are comparing the performance of: * Using JavaScript's built-in `Math.sqrt` function * Using the custom Quake Invert Sqrt algorithm implemented in `Q_rsqrt` **Pros and Cons** * **Built-in Math.sqrt**: Pros: + Well-maintained and widely supported by browsers. + Typically faster due to optimized implementation. Cons: + May use more memory or have more complex code. * **Quake Invert Sqrt algorithm**: Pros: + Can be faster than built-in `Math.sqrt` for certain inputs. + May require less memory. Cons: + Less well-maintained and supported by browsers. + Requires custom implementation. **Library usage** The test case using the Quake Invert Sqrt algorithm uses a library called "Quake". Quake is a vectorized math library that provides optimized implementations for various mathematical operations, including inverse square root. The `Q_rsqrt` function in the benchmark definition is an example of this library's implementation. **Special JS feature/syntax** There are no special JavaScript features or syntax used in these benchmarks. They only use standard JavaScript functions and data types. **Other alternatives** If you're interested in testing alternative methods for calculating inverse square roots, you could consider using: * The `v8::math` library (available in the Chromium source code) which provides a similar implementation to Quake. * Other custom implementations or libraries that provide optimized inverse square root functions. * Using approximation techniques, such as Taylor series expansion, to calculate inverse square roots. Keep in mind that these alternatives might not be directly comparable to the built-in `Math.sqrt` function or the Quake Invert Sqrt algorithm, and may require additional considerations for performance, memory usage, and code complexity.
Related benchmarks:
Fast Sqrt
Fast Sqrt 2234234
Inverse square root (fixed)
Fast Sqrt0
Comments
Confirm delete:
Do you really want to delete benchmark?