Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
strict mode function vs normal function
(version: 1)
Comparing performance of:
strict vs normal
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
function one(){'use strict'; return arguments} function two(){return arguments}
Tests:
strict
for(let i = 3000; --i;)one(i)
normal
for(let i = 3000; --i;)two(i)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
strict
normal
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
strict
1537.5 Ops/sec
normal
1566.6 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark you've provided compares two different types of JavaScript functions: one operating in **strict mode** and the other in **normal (non-strict) mode**. ### Options Compared: 1. **Strict Mode Function (one)**: - Defined using `'use strict';`, which enables strict mode for the function. - It returns the `arguments` object, which represents the passed arguments as an array-like object. 2. **Normal Function (two)**: - This function does not include the `'use strict';` directive. - Like the first function, it also returns the `arguments` object in a similar way. ### Performance Results: The benchmark results indicate the following: - **Normal Function** Executions per Second: 1566.58 - **Strict Mode Function** Executions per Second: 1537.48 The normal function is faster in this case, suggesting that the overhead introduced by strict mode may be slightly detrimental to performance in this specific benchmark compared to non-strict mode. ### Pros and Cons: #### Strict Mode (Function one): **Pros**: - Helps catch common coding mistakes, such as assigning to undeclared variables, which can lead to safer code. - Disallows certain actions, like deleting variables or using duplicate parameter names, resulting in more predictable behavior. **Cons**: - May incur slight performance penalties, as seen in the benchmark results, due to additional checks for violations of strict rules. - Some older JavaScript features and patterns may not work or behave consistently in strict mode, which can be a challenge for legacy code. #### Normal Mode (Function two): **Pros**: - Easier to write and can be more forgiving, which can be beneficial when working quickly or with less seasoned JavaScript developers. - Generally, it incurs less overhead in terms of performance during function execution, as indicated by the benchmark. **Cons**: - Leaves potential for common mistakes, which can lead to bugs that are harder to track. - May allow unintended global variable declarations, making the code less manageable in larger applications. ### Other Considerations: - Potential use cases for strict mode are in projects where maintainability and robust error handling are priorities, while normal mode may be more appropriate for quick scripts or in environments where performance is the utmost concern. ### Alternatives: While the benchmark specifically compares strict vs. non-strict functions, alternatives to using function strictness for performance include: - **Using ES6 Arrow Functions**: They provide shorter syntax but do not have their own `this` context. - **Using Modern JavaScript Features**: Such as modules, which can help manage scope and encapsulate functionality. - **Optimizing Performance**: Through techniques such as minimizing the use of the arguments object (using rest parameters in ES6) or switch to ES6 features entirely, which can enhance performance and maintainability. ### Conclusion: This benchmark provides valuable insights into the performance differences between strict and normal functions in JavaScript. Though strict mode can potentially hinder performance, its advantages in error prevention and program robustness are significant, making it essential to balance performance with code quality in real-world applications.
Related benchmarks:
Return true vs return;
new Function vs Literal
eval vs new Function vs regular function
JS Operator vs Function
eval vs new Function without cached parsing
eval vs new Function1
function vs new function
eval vs new Function vs vanilla
Const vs Function
Comments
Confirm delete:
Do you really want to delete benchmark?