Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Float32 vs Float64
(version: 0)
Comparing performance of:
create f32 vs create f64 vs set f32 vs set f64 vs iterate and set f32 vs iterate and set f64 vs add and multiply f32 vs add and multiply f64
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var length = 1e6; var f32_a = Float32Array.from({length}, Math.random); var f32_b = Float32Array.from({length}, Math.random); var f64_a = Float64Array.from({length}, Math.random); var f64_b = Float64Array.from({length}, Math.random);
Tests:
create f32
new Float32Array(length);
create f64
new Float64Array(length);
set f32
f32_a.set(f32_b);
set f64
f64_a.set(f64_b);
iterate and set f32
for (let i = 0; i < length; i++) { f32_a[i] = f32_b[i]; }
iterate and set f64
for (let i = 0; i < length; i++) { f64_a[i] = f64_b[i]; }
add and multiply f32
for (let i = 0; i < length; i++) { f32_a[i] = f32_b[i] + f32_b[i] * 2; }
add and multiply f64
for (let i = 0; i < length; i++) { f64_a[i] = f64_b[i] + f64_b[i] * 2; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (8)
Previous results
Fork
Test case name
Result
create f32
create f64
set f32
set f64
iterate and set f32
iterate and set f64
add and multiply f32
add and multiply f64
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 break down the provided benchmark definition and test cases to understand what is being tested. **What is being tested?** The primary goal of this benchmark is to compare the performance of two data types in JavaScript: `Float32Array` (32-bit floating-point numbers) and `Float64Array` (64-bit floating-point numbers). More specifically, the test suite covers various operations: 1. Creating instances of both `Float32Array` and `Float64Array`. 2. Setting values in these arrays using direct assignment (`set`) or iterating over the array to set individual values. 3. Performing arithmetic operations on values stored in these arrays (addition and multiplication). **Options compared** The test suite compares two main options: 1. **Creating instances of `Float32Array` and `Float64Array`**: This option measures the overhead of creating instances of these data types, which may involve initializing internal buffers or allocating memory. 2. **Setting values in these arrays using direct assignment or iteration**: This option assesses the efficiency of setting individual values within the arrays, which may affect performance depending on the array size and operation complexity. **Pros and cons of each approach** 1. **Creating instances**: * Pros: Quick initialization, easy to implement. * Cons: May involve overhead due to internal buffer management or memory allocation. 2. **Direct assignment**: * Pros: Fast and straightforward setting of individual values. * Cons: Can lead to slower performance if array indices are accessed sequentially (e.g., `f32_a[i] = f32_b[i];`). 3. **Iteration**: * Pros: Efficient for large arrays, as it avoids sequential access to array indices. * Cons: Requires additional loop logic and may be less readable. **Library usage** The benchmark uses the following libraries: 1. `Float32Array` and `Float64Array`: Built-in JavaScript typed array classes. 2. `Math.random()`: A built-in JavaScript function for generating random numbers. No external libraries are used in this benchmark. **Special JS feature or syntax** None of the test cases rely on any special JavaScript features or syntax that would affect performance, such as async/await, promises, or Web Workers. Overall, this benchmark aims to provide a comprehensive comparison of performance between `Float32Array` and `Float64Array` in various common operations, helping developers understand the trade-offs between using these data types in their applications.
Related benchmarks:
toFixed vs toPrecision vs Math.round() vs Math.floorfaster test
floor vs trunc vs bit shift
crypto.getRandomValues vs Math.random()
new Uint8Array() vs Uint8Array.from()
new Uint8Array() vs Uint8Array.from() reverse
Comments
Confirm delete:
Do you really want to delete benchmark?