Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Function Instantiation
(version: 0)
Comparing performance of:
new Function vs Regular
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var newFuncMaker = new Function("return new Function(\"return Math.random().toString(36).substring(7).includes('x');\")"); var regularFuncMaker = new Function("return function () {return Math.random().toString(36).substring(7).includes('x');}");
Tests:
new Function
newFuncMaker()
Regular
regularFuncMaker()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new Function
Regular
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 benchmark and its test cases. **What is tested:** The provided JSON represents two JavaScript microbenchmarks: 1. **Function Instantiation**: This test compares the performance of creating a new function using two different approaches: * `newFuncMaker()`: creates a function that returns another function with a specific behavior (returns `Math.random().toString(36).substring(7).includes('x')`). * `regularFuncMaker()`: creates a regular function with a similar behavior. 2. **Function Call**: The benchmark also includes two test cases: * `new Function`: calls the created function from step 1 using the `new Function()` syntax. * `Regular`: calls the created function from step 1 without using the `new Function()` syntax. **Options compared:** The benchmark compares two approaches for creating a new function: * **`newFuncMaker()`**: creates a function that returns another function with a specific behavior. This approach is likely used to test the overhead of creating a nested function. * **`regularFuncMaker()`**: creates a regular function with the same behavior as `newFuncMaker()`. This approach is likely used to test the performance of a simple function call. **Pros and Cons:** 1. **`newFuncMaker()`**: * Pros: Tests the overhead of creating a nested function, which can be an interesting optimization opportunity. * Cons: May introduce additional overhead due to the creation of an inner function. 2. **`regularFuncMaker()`**: * Pros: Simpler and more straightforward approach, likely with less overhead. * Cons: May not accurately represent real-world scenarios where functions are created frequently. Other considerations: * The benchmark uses a specific behavior for the created function (`Math.random().toString(36).substring(7).includes('x')`), which is unlikely to occur in most real-world applications. This might affect the accuracy of the results. * There is no test case that calls the created function directly, only through the `new Function()` syntax or without it. **Libraries and special JS features:** There are no libraries used in this benchmark. **Special JS feature:** The `new Function()` syntax is a built-in JavaScript feature for creating new functions. It's not a modern JavaScript feature, but rather a legacy syntax that was introduced in ECMAScript 5. **Alternatives:** If you want to create benchmarks similar to these, you can consider the following alternatives: * Use a more modern approach like `Function()` (without the `new` keyword) or a library like `function-expression`. * Create a benchmark with different types of functions, such as arrow functions or classes. * Experiment with different optimization techniques, such as inlining or caching, to see their impact on performance. Keep in mind that creating benchmarks requires careful consideration of factors like hardware, software, and version-specific behavior. Always aim for accurate and representative test cases to ensure reliable results.
Related benchmarks:
eval vs new Function (Sample JS Functions)
eval vs new Function vs function(Sample JS Functions)
new Function vs function
eval vs new Function vs function(Sample JS Functions)2
Comments
Confirm delete:
Do you really want to delete benchmark?