Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
eval vs new Function call
(version: 0)
Comparing performance of:
eval vs new Function
Created:
6 years ago
by:
Guest
Jump to the latest result
Tests:
eval
eval("2 * 3");
new Function
(new Function("return 2 * 3"))();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
eval
new Function
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
eval
1623822.1 Ops/sec
new Function
793926.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases. **What is tested?** The benchmark tests two different approaches to perform arithmetic operations: `eval` and creating a new function using `Function`. The purpose of these tests is to compare their performance, specifically in terms of how many executions per second they can handle. **Options compared** * **eval**: This function takes a string as an argument and evaluates it as JavaScript code. In this case, the input strings are "2 * 3" and return 6. * **new Function**: This creates a new function that executes the provided code when called with no arguments. The input strings are also "2 * 3", but they're passed to the newly created function. **Pros and cons of each approach** * **eval** * Pros: * Simple to use; you just pass your JavaScript expression as a string. * Can be used for complex expressions, not limited to simple arithmetic operations. * Cons: * Can pose security risks if the input is not validated properly (e.g., allowing malicious code execution). * Generally slower than creating a new function due to overhead from parsing and compiling the string. * **new Function** * Pros: * More secure than `eval` since it doesn't execute arbitrary code directly. * Faster for simple arithmetic operations, as there's less overhead compared to parsing and compiling a string. * Cons: * Requires creating a new function object, which can be slower due to the overhead of creating a new scope and binding the function's execution context. * Can be more verbose than using `eval`. **Libraries used** None are explicitly mentioned in this benchmark. **Special JavaScript features or syntax** No specific features or syntax are being tested here; it is a basic arithmetic operation comparison.
Related benchmarks:
eval vs new Function
eval vs new Function #2
eval() vs new Function()
eval vs new Function (fix)
window.eval function vs new Function1
Comments
Confirm delete:
Do you really want to delete benchmark?