Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
eval vs new Function vs function 1338
(version: 0)
Comparing performance of:
eval vs new Function vs function in code
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var func = new Function("return 2 * 3"); function funcs() { return 2 * 3; } eval("function funce() { return 2 * 3; }");
Tests:
eval
funce();
new Function
func();
function in code
funcs();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
eval
new Function
function in code
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):
I'll break down the provided benchmark definition and test cases for you. **Benchmark Definition:** The benchmark is comparing three ways to create and call a simple function in JavaScript: 1. **`eval`**: The `eval` function executes a string as JavaScript code. 2. **`new Function`**: The `Function` constructor creates a new function object that can be called like any other function. 3. **`function` (inline function)**: A inline function, defined directly in the code. **Options Compared:** * Performance of each option on different browsers and devices **Pros and Cons:** 1. **`eval`**: * Pros: Simple to use, flexible for complex expressions * Cons: Can be slow, vulnerable to security issues (e.g., code injection) 2. **`new Function`**: * Pros: Fast, secure, and sandboxed * Cons: Requires a function name and parameters, more verbose 3. **`function` (inline function)**: * Pros: Lightweight, easy to use, and faster than `eval` * Cons: Limited flexibility compared to `new Function` **Library Usage:** None of the test cases uses any external libraries. **Special JS Features or Syntax:** None mentioned in this benchmark definition. However, it's worth noting that some features like ES6 arrow functions (`=>`) are not tested here, but might be relevant for more comprehensive benchmarks. **Other Alternatives:** For creating and calling small functions, other options could include: * **Arrow functions**: A concise way to define small, single-expression functions (e.g., `() => 2 * 3`) * **Function expressions**: Similar to inline functions, but can be defined outside the main code block (e.g., `const func = function funce() { return 2 * 3; };`) * **Closures**: A way to create functions that have access to their own scope and can capture variables from their surrounding context. In this specific benchmark, the focus is on performance comparison between three existing methods: `eval`, `new Function`, and inline function.
Related benchmarks:
eval vs new Function v3
eval vs new Function (fix)
window.eval function vs new Function
window.eval function vs new Function1
window.eval function vs new Function2
Comments
Confirm delete:
Do you really want to delete benchmark?