Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Passing objects with raw values vs passing just raw values vs array of values (add obj & array init cost)
(version: 4)
Updated because it looks like Firefox optimizes away the entire test
Comparing performance of:
Pass object vs Pass object with new obj vs Pass raw values vs Pass array vs Pass array with new array
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var a = "Here's a string value"; var b = 5; // and a number var c = false; var object = { a, b, c } var array = [ a, b, c ]; var passObject = (obj) => { return obj.a.length + obj.b * obj.c ? 2 : 1; } var passRawValues = (val_a, val_b, val_c) => { return val_a.length + val_b * val_c ? 2 : 1; } var passArray = (arr) => { return arr[0].length + arr[1] * arr[2] ? 2 : 1; } var x = 0;
Tests:
Pass object
x << 1; x ^= passObject(object);
Pass object with new obj
x << 1; x ^= passObject({ a: a, b: b, c: c });
Pass raw values
x << 1; x ^= passRawValues(a, b, c);
Pass array
x << 1; x ^= passArray(array);
Pass array with new array
x << 1; x ^= passArray(array = [a, b, c]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Pass object
Pass object with new obj
Pass raw values
Pass array
Pass array with new array
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 provided benchmark definition and test cases. **Benchmark Definition:** The provided JSON represents a JavaScript microbenchmark that measures the performance of passing objects, raw values, and arrays in different scenarios. The benchmark is designed to compare the execution times of four functions: 1. `passObject(object)`: Passes an object with properties `a`, `b`, and `c`. 2. `passRawValues(a, b, c)`: Passes three raw values (`a` as a string, `b` as a number, and `c` as a boolean). 3. `passArray(array)`: Passes an array containing the same elements as in `passObject(object)`. The benchmark also includes two variations: 4. `passObject_with_new_obj`: Passes an object with properties `a`, `b`, and `c`, created on the fly. 5. `passRawValues_with_new_args`: Passes raw values (`a`, `b`, and `c`) created on the fly. **Comparison of Options:** The benchmark compares the performance of passing objects, raw values, and arrays in different scenarios: * Passing an object vs passing just raw values or an array. * Creating an object or array on the fly vs using pre-existing ones. **Pros and Cons:** 1. **Passing an object**: Pros - can be more efficient than passing individual elements (raw values or array). Cons - may incur additional overhead due to object creation and property access. 2. **Passing raw values**: Pros - typically faster than passing objects, as it avoids the overhead of object creation and property access. Cons - may not take into account the relationships between individual values (e.g., `a` is a string, while `b` is an integer). 3. **Passing an array**: Pros - similar to passing raw values in terms of speed, but can be more efficient if the elements have relationships (e.g., all are strings). Cons - may incur additional overhead due to array creation and indexing. **Library:** None of the test cases explicitly use any libraries. However, some JavaScript features used in the benchmark definition include: * Template literals (`var x = 0;`) * Object literal syntax (`var object = { a, b, c };`) These features are part of the ECMAScript standard and are widely supported by most modern browsers. **Special JS Features or Syntax:** The benchmark uses some special JavaScript features, including: * The `<<` operator (left shift) for bitwise operations. * The `^=` operator (bitwise XOR assignment) for assignments that modify a variable using bitwise operations. These features are not typically used in everyday JavaScript development but can be useful in specific contexts.
Related benchmarks:
Spread vs Object.assign (modify ) vs Object.assign (new)
Object.assign vs spread operatora
Spread operator vs Object.assign
Object assign vs spread operator benchmark
Object spread
Comments
Confirm delete:
Do you really want to delete benchmark?