Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
new with empty args list vs new with no args list
(version: 1)
Comparing performance of:
empty args list vs no args list
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
empty args list
new Number()
no args list
new Number
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
empty args list
no args list
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 131 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
empty args list
3662014.5 Ops/sec
no args list
3688006.0 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark defined in the provided JSON tests the performance of number creation in JavaScript using two different approaches: `new Number()` with an empty arguments list and `new Number` with no arguments being passed. Here’s a breakdown of the test cases, their purpose, and some considerations regarding both approaches. ### Benchmark Description 1. **Test Cases**: - **empty args list**: This case uses `new Number()` which explicitly calls the constructor without any parameters. - **no args list**: This case uses `new Number` which is a shorthand way of writing the constructor call without parentheses. ### Performance Results - The performance results show that both approaches are quite close in their execution speed: - **empty args list**: 3,713,474.75 executions per second - **no args list**: 3,694,844.5 executions per second ### Pros and Cons of Each Approach - **`new Number()` (empty args list)**: - **Pros**: - Explicitly denotes that the constructor is intended to be called, which may improve code readability for some developers. - Allows for consistency if other constructor calls in the code use parentheses. - **Cons**: - Slightly lower performance in this benchmark. - **`new Number` (no args list)**: - **Pros**: - Marginally better performance according to the benchmark results. - More concise syntax, which may appeal to developers favoring brevity. - **Cons**: - Slightly less explicit, which could cause some confusion, particularly for less experienced developers. ### Additional Considerations - **JavaScript Constructor Behavior**: Both approaches utilize JavaScript’s `Number` constructor, which creates a new `Number` object. If passed no arguments, both will return a `Number` object representing the primitive value `0`. - **Browser Variation**: The benchmark results come from tests conducted on Chrome Mobile 131 running on an Android device. Performance may vary across different browsers and devices due to differences in how JavaScript engines implement constructors. ### Alternatives While both proposed approaches are valid, developers may also consider: - **Primitive Values**: Simply using the primitive `0` or other numeric literals (e.g., `5`, `10.5`) directly instead of creating `Number` objects unless an object is specifically needed. - **Object Wrapping with Other Constructs**: Using `Object.create(Number.prototype)` if a more complex numeric object behavior is needed. However, this is less common and typically slower than direct number creation. - **Typed Arrays**: For performance-critical applications dealing with a large set of numeric values, using typed arrays in JavaScript (like `Float32Array` or `Int32Array`) might provide more optimized storage and performance. In summary, while both options tested are functionally equivalent with negligible performance differences, choosing between them may come down to personal or team coding standards and preferences. Different scenarios, especially those involving high-performance computations, may call for alternative approaches like primitive values or typed arrays.
Related benchmarks:
isNull lodash vs native
length vs length > 0
eval vs new Function call
Number() vs +
null vs !
String() vs toString
Array() vs new Array()
Number vs Number.parseFloat
eval vs new Function - The correct way
new array vs new set
Comments
Confirm delete:
Do you really want to delete benchmark?