Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
(ColorfulCakeChen) Measure That Async () 7
(version: 7)
Comparing performance of:
1 second vs 10 seconds vs 60 seconds
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function createWaitPromise( milliseconds ) { return new Promise( ( resolve, reject ) => { setTimeout( resolve, milliseconds ); }); }
Tests:
1 second
if ( globalThis.SecondsPromise1 && globalThis.SecondsPromise10 && globalThis.SecondsPromise60 ) globalThis.SecondsPromise1 = globalThis.SecondsPromise10 = globalThis.SecondsPromise60 = null; if ( !globalThis.SecondsPromise1 ) globalThis.SecondsPromise1 = createWaitPromise( 1000 * 1 ); /* Just busy waiting. */
10 seconds
if ( !globalThis.SecondsPromise10 ) globalThis.SecondsPromise10 = createWaitPromise( 1000 * 10 ); /* Just busy waiting. */
60 seconds
if ( !globalThis.SecondsPromise60 ) globalThis.SecondsPromise60 = createWaitPromise( 1000 * 60 ); /* Just busy waiting. */
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
1 second
10 seconds
60 seconds
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 provided benchmark and its components. **Benchmark Definition JSON** The benchmark is defined by a JSON object that contains information about the test. The relevant fields are: * `Name`: A descriptive name for the benchmark. * `Description`: An empty string, indicating no description for this benchmark. * `Script Preparation Code`: A JavaScript function `createWaitPromise` that returns a promise that resolves after a specified number of milliseconds. * `Html Preparation Code`: An empty string, indicating no HTML preparation code is needed. The script defines a global object `globalThis` and checks if certain properties (`SecondsPromise1`, `SecondsPromise10`, and `SecondsPromise60`) are defined. If any of them are not defined, they are assigned the return value of `createWaitPromise` with different time intervals (1 second, 10 seconds, or 60 seconds). The comments indicate that these properties are used to create promises that can be waited upon. **Test Cases** The benchmark consists of three test cases: * Test case 1: Waits for 1 second. * Test case 2: Waits for 10 seconds. * Test case 3: Waits for 60 seconds. Each test case has a `Benchmark Definition` field that contains the actual JavaScript code to be executed. The code checks if any of the promises are defined and, if not, assigns them using `createWaitPromise`. The comments indicate that these properties are used to create promises that can be waited upon. **Pros and Cons** The use of promises in this benchmark has both pros and cons: Pros: * Promises provide a way to handle asynchronous code in a more elegant and readable manner. * They allow for better error handling and support for callbacks. Cons: * The use of promises might introduce additional overhead due to the creation and resolution of promise objects. * In this specific case, the benefits of using promises are limited by the fact that the test cases only wait for a short period (1-60 seconds) before resolving. **Library: `globalThis`** The `globalThis` object is not a standard library in JavaScript. It's an extension that provides access to global variables and functions on modern browsers. The `globalThis` object is used here to access the properties `SecondsPromise1`, `SecondsPromise10`, and `SecondsPromise60`. **Special JS Feature: Arrow Functions** The use of arrow functions (`() => { ... }`) in the benchmark definition code is a feature introduced in ECMAScript 2015 (ES6). It provides a concise way to define small, one-time-use functions. **Other Alternatives** If this benchmark were to be rewritten, other alternatives could include: * Using `setTimeout` and `clearTimeout` instead of promises. * Using a third-party library like `async-promise-executor` or `bluebird` for promise handling. * Using a testing framework that provides built-in support for async testing. It's worth noting that the choice of implementation depends on the specific requirements and constraints of the benchmark.
Related benchmarks:
Multipromise resulter
async for vs promise all (setTimeout version)
needless async impact
(ColorfulCakeChen) delayValue 8
Comments
Confirm delete:
Do you really want to delete benchmark?