Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Computation single optimization with destructuring vs application fn
(version: 0)
Comparing performance of:
apply 1 vs single 1 vs apply 2 vs single 2 vs apply 3 vs single 3
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
const data = ["hello", " ", "world"]; const applicators = [ ({ fn }) => fn(), ({ fn, deps }) => fn(read(deps[0])), ({ fn, deps }) => fn(read(deps[0]), read(deps[1])), ({ fn, deps }) => fn(...deps.map(read)) ] let cid = 0; var dep1 = { id: 0 }; var dep2 = { id: 1 }; var dep3 = { id: 2 }; function sampleArgs1(_0) { return _0; } function sampleArgs2(_0, _1) { return _0 + _1; } function sampleArgs3(_0, _1, _2) { return _0 + _1 + _2; } function sampleDes1(_0) { return _0; } function sampleDes2([_0, _1]) { return _0 + _1; } function sampleDes3([_0, _1, _2]) { return _0 + _1 + _2; } function createApplyComputation(fn, deps) { return { id: cid++, fn, deps, apply: applicators[deps.length] }; } function createSingleComputation(fn, deps, isSingle) { return { id: cid++, fn, deps, isSingle }; } function execApplyComputation(c) { return c.apply(c); } function execSingleComputation(c) { if (c.isSingle) { return c.fn(read(c.deps)); } return c.fn(c.deps.map(read)); } function read(s) { return data[s.id]; }
Tests:
apply 1
execApplyComputation(createApplyComputation(sampleArgs1, [dep1]));
single 1
execSingleComputation(createSingleComputation(sampleDes1, dep1, true));
apply 2
execApplyComputation(createApplyComputation(sampleArgs2, [dep1, dep2]));
single 2
execSingleComputation(createSingleComputation(sampleDes2, [dep1, dep2]));
apply 3
execApplyComputation(createApplyComputation(sampleArgs3, [dep1, dep2, dep3]));
single 3
execSingleComputation(createSingleComputation(sampleDes3, [dep1, dep2, dep3]));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
apply 1
single 1
apply 2
single 2
apply 3
single 3
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 benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The benchmark compares two approaches to executing a computation: applying a function to an array of dependencies (`execApplyComputation`) versus using a single, optimized execution path (`execSingleComputation`). **Test Cases** There are four test cases: 1. `apply 1`: Applies the `sampleArgs1` function to a single dependency (`dep1`). 2. `single 1`: Executes the `sampleDes1` function with a single dependency (`dep1`) using the optimized path. 3. `apply 2`: Applies the `sampleArgs2` function to two dependencies (`dep1` and `dep2`). 4. `single 2`: Executes the `sampleDes2` function with two dependencies (`dep1` and `dep2`) using the optimized path. 5. `apply 3`: Applies the `sampleArgs3` function to three dependencies (`dep1`, `dep2`, and `dep3`). 6. `single 3`: Executes the `sampleDes3` function with three dependencies (`dep1`, `dep2`, and `dep3`) using the optimized path. **Comparison** The benchmark compares the execution time of each test case: * `execApplyComputation`: Applies a function to an array of dependencies. * `execSingleComputation`: Executes a single, optimized function with an array of dependencies. **Library: `read`** The `read` function is used to map dependency IDs to their corresponding values in the `data` array. Its purpose is to provide access to the dependencies used by each function. **Special JS Feature/Syntax** There doesn't seem to be any special JavaScript features or syntax being tested here. The benchmark focuses on comparing two different approaches to executing a computation, rather than exploring specific language features. **Pros and Cons of Each Approach** Here's a brief summary of the pros and cons of each approach: * `execApplyComputation`: + Pros: Decoupling function execution from dependency mapping can improve flexibility and maintainability. + Cons: May incur additional overhead due to repeated dependency lookups. * `execSingleComputation`: + Pros: Optimized for performance, as it eliminates the need for repeated dependency lookups. + Cons: Tightly couples function execution with dependency mapping, making it less flexible. **Benchmark Results** The benchmark results show varying execution times across different test cases. However, without more context or analysis, it's difficult to draw definitive conclusions about which approach is faster or more efficient.
Related benchmarks:
single-upstream-vs-switch-apply-2
Computation single optimization vs application fn
Computation single optimization with destructuring vs application switch with single dep
Computation single optimization with destructuring vs application fn - 1000 runs
Comments
Confirm delete:
Do you really want to delete benchmark?