Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Function overhead
(version: 0)
Comparing performance of:
eval vs new Function vs Normal
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var func = new Function("return 2 * 3"); var fn = function() { return 2 * 3; };
Tests:
eval
eval("2 * 3");
new Function
func();
Normal
fn();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
eval
new Function
Normal
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):
**Overview of the Benchmark** The provided JSON represents a JavaScript microbenchmark created on MeasureThat.net. The benchmark is designed to test the overhead of different approaches to define and call functions. **Benchmark Definition** The benchmark definition is a set of scripts that are executed in sequence to measure their performance. There are three test cases: 1. **Normal**: This test case defines a function using the `function` keyword, which is the most common way to define a function in JavaScript. 2. **new Function**: This test case uses the `Function` constructor to define a function, creating a new function object. 3. **eval**: This test case uses the `eval` function to evaluate an expression and return its result. **Options Compared** The benchmark compares the performance of these three approaches: * **Normal**: Using the `function` keyword to define a function. * **new Function**: Using the `Function` constructor to define a function. * **eval**: Using the `eval` function to evaluate an expression. **Pros and Cons of Each Approach** Here's a brief summary of the pros and cons of each approach: 1. **Normal (using the `function` keyword)**: * Pros: Fast, efficient, and widely supported. * Cons: None notable. 2. **new Function (using the `Function` constructor)**: * Pros: Provides more control over function creation, can be useful in certain scenarios. * Cons: Can be slower than the `function` keyword due to the overhead of creating a new function object. 3. **eval**: * Pros: Dynamic and flexible, can evaluate expressions on-the-fly. * Cons: Generally slower than the other two approaches due to the overhead of parsing and executing the expression. **Library Used** None of the benchmark cases use any external libraries. **Special JS Feature or Syntax** The `Function` constructor is a special feature in JavaScript that allows creating function objects dynamically. It's a built-in object that provides more control over function creation than the `function` keyword. **Other Alternatives** If you want to test other approaches to defining functions, you could consider adding additional benchmark cases, such as: * Using arrow functions (`() => { ... }`) * Using closures and self-invoking anonymous functions (`(function() {...})()`) * Using a library like `es6-function` that provides more control over function creation Keep in mind that these alternatives might not be relevant to the specific use case of this benchmark, but they could provide additional insights into the performance characteristics of different approaches.
Related benchmarks:
Rounding methods
Power vs Square Root functions
toFixed vs toPrecision vs Math.round() vs Math.floorfast vs MDN round_to_precision
decimal.js versus native precision
roundDecimal() with Math.pow vs. Unary and toPrecision()
Comments
Confirm delete:
Do you really want to delete benchmark?