Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Promisify test
(version: 0)
Comparing performance of:
x1 vs x2
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const delay = (ms) => new Promise(resolve => { setTimeout(resolve, ms); }); let deposit; const pGen = async ()=> { const res = await new Promise(resolve => { resolve(deposit); }); if (res) { return res; } await delay(0.5e3); return pGen(); }; const r = (t) => setTimeout(() => deposit = 1,t) var main = async (t) => { r(t); console.log(await pGen()); }
Tests:
x1
main(5e3);
x2
main(5e3);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
x1
x2
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
x1
424907.7 Ops/sec
x2
605565.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark definition and test cases to explain what's being tested, the options compared, pros and cons of each approach, library usage, special JavaScript features or syntax, and alternatives. **Benchmark Definition** The benchmark is testing the performance of promisified asynchronous functions. Promisify is a technique used to convert synchronous functions into asynchronous ones using promises. Here's a high-level overview of what's being tested: 1. A deposit value is initialized as `null`. 2. An asynchronous function `pGen` is defined, which takes an unknown amount of time to resolve (due to the `delay` function). 3. The function returns the deposited value if it exists; otherwise, it waits for a 0.5-second delay and recursively calls itself. 4. A main function `main` is defined, which sets a timeout to deposit a value of 1 at a specified time `t`. 5. The benchmark script prepares the environment by defining these functions. **Options Compared** The test case uses two different approaches: 1. **Recursive approach**: Using the `pGen` function with a recursive call. 2. **Non-recursive approach**: Without using recursion in the `pGen` function, instead relying on timeouts to achieve the desired delay. Pros and Cons of each approach: **Recursive approach** Pros: * Easier to understand and implement * Less memory overhead due to fewer stack frames Cons: * Performance might be slower due to the recursive call * Risk of stack overflow for large values of `t` **Non-recursive approach** Pros: * Potential performance improvement due to avoiding recursive calls * Less risk of stack overflow for large values of `t` Cons: * More complex to implement and understand * Requires careful tuning of timeouts to achieve the desired delay **Library Usage** The benchmark definition does not explicitly use any libraries. However, it relies on built-in JavaScript features such as promises and async/await. **Special JavaScript Features or Syntax** This benchmark uses some advanced JavaScript features: 1. **Async functions**: The `pGen` function is defined as an asynchronous function using the `async` keyword. 2. **Promises**: The `new Promise(resolve => { ... })` construct creates a promise that resolves when the specified code block is executed. 3. **Timeouts**: The `setTimeout` function is used to set a delay in milliseconds. **Alternatives** Other alternatives for testing promisified asynchronous functions could include: 1. Using a testing framework like Jest or Mocha, which provides built-in support for benchmarking and testing JavaScript code. 2. Utilizing a library like Benchmark.js, which provides a simple and efficient way to write benchmarks. 3. Implementing a custom benchmarking loop using a language like C++ or Rust, which can provide better performance than JavaScript. Keep in mind that the specific choice of alternative will depend on the project's requirements and constraints.
Related benchmarks:
Multipromise resulter
Promise vs Async Await
Check await or just await
Promise vs Async Await(2)
Comments
Confirm delete:
Do you really want to delete benchmark?