Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
chainedvsfor
(version: 0)
Comparing performance of:
chained vs forLoop vs forLoop2
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var chainedArr = [] var forLoopArr = [] var forLoop2Arr = [] function doSomething(arr, age) { arr.push(age) } function chained() { var arr = people100 arr .filter(item => item.age < 30) .map(item => item.age) .forEach(item => doSomething(chainedArr, item)) } function forLoop() { var arr = people100 for (var i = 0; i < arr.length; i++) { if (arr[i].age < 30) { doSomething(forLoopArr, arr[i].age) } } } function forLoop2() { var arr = people100 for (var i = 0; i < arr.length; i++) { var item = arr[i] if (item.age < 30) { doSomething(forLoop2Arr, item.age) } } } var people100 = [{"name":"rural sex","age":1},{"name":"taut challenge","age":29},{"name":"passionate truck","age":40},{"name":"purple director","age":30},{"name":"weepy chain","age":95},{"name":"sandy land","age":106},{"name":"dead whole","age":60},{"name":"humongous collar","age":73},{"name":"best member","age":1},{"name":"outlying anxiety","age":88},{"name":"hospitable return","age":12},{"name":"idolized reflection","age":76},{"name":"meager wake","age":9},{"name":"klutzy cell","age":42},{"name":"dreary reveal","age":83},{"name":"criminal mother","age":75},{"name":"fake alarm","age":44},{"name":"great alternative","age":100},{"name":"untimely count","age":9},{"name":"useless proof","age":29},{"name":"metallic introduction","age":28},{"name":"unsteady campaign","age":77},{"name":"nutty finish","age":34},{"name":"impressionable hour","age":45},{"name":"tangible document","age":72},{"name":"overlooked forever","age":60},{"name":"prize employer","age":3},{"name":"expensive growth","age":48},{"name":"regal employee","age":94},{"name":"upset courage","age":86},{"name":"dopey poem","age":91},{"name":"loud past","age":46},{"name":"self-reliant tension","age":20},{"name":"weighty creative","age":23},{"name":"kaleidoscopic coach","age":59},{"name":"dismal creative","age":75},{"name":"fuzzy statement","age":6},{"name":"abandoned highway","age":41},{"name":"odd listen","age":53},{"name":"muddy horse","age":98},{"name":"imperturbable profession","age":101},{"name":"jumpy tax","age":76},{"name":"spiteful board","age":40},{"name":"fine plate","age":44},{"name":"jagged child","age":31},{"name":"humming historian","age":21},{"name":"cheerful manager","age":24},{"name":"present hurry","age":98},{"name":"unwitting limit","age":96},{"name":"mellow touch","age":23},{"name":"far-off item","age":87},{"name":"untrue proof","age":25},{"name":"angry lead","age":110},{"name":"pleased essay","age":29},{"name":"offbeat will","age":22},{"name":"strong draft","age":5},{"name":"miserly foot","age":97},{"name":"violet season","age":35},{"name":"prime bell","age":33},{"name":"scrawny recording","age":34},{"name":"sweltering bottom","age":109},{"name":"drab soup","age":34},{"name":"exhausted fun","age":23},{"name":"soupy primary","age":116},{"name":"direct double","age":39},{"name":"trifling campaign","age":61},{"name":"gloomy print","age":6},{"name":"small storm","age":81},{"name":"essential speaker","age":107},{"name":"assured mention","age":113},{"name":"tangible teach","age":90},{"name":"jumbo war","age":2},{"name":"dull title","age":75},{"name":"shocked throat","age":37},{"name":"assured claim","age":96},{"name":"infatuated profit","age":94},{"name":"straight negative","age":85},{"name":"rocky transportation","age":45},{"name":"hilarious east","age":2},{"name":"exotic suck","age":53},{"name":"ill-fated cap","age":41},{"name":"adorable tooth","age":109},{"name":"lumpy current","age":30},{"name":"negative convert","age":28},{"name":"misguided brief","age":30},{"name":"starry bone","age":115},{"name":"timely savings","age":53},{"name":"unlucky wine","age":93},{"name":"vicious tear","age":68},{"name":"intentional bread","age":77},{"name":"recent son","age":90},{"name":"pure shelter","age":32},{"name":"tiny devil","age":102},{"name":"pure direction","age":83},{"name":"enormous bedroom","age":4},{"name":"long-term stay","age":99},{"name":"real round","age":37},{"name":"limited computer","age":110},{"name":"unpleasant style","age":10},{"name":"unwritten sail","age":44}]
Tests:
chained
chained()
forLoop
forLoop()
forLoop2
forLoop2()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
chained
forLoop
forLoop2
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 JSON and explain what's being tested. **Benchmark Definition** The benchmark definition is an object that describes the JavaScript function to be executed. In this case, we have three test cases: * `chained()`: This function calls another function recursively without any arguments. * `forLoop()`: This function uses a traditional `for` loop to iterate over an array and perform some operation on each element. * `forLoop2()`: Similar to `forLoop()`, but with a slightly different implementation. **Individual Test Cases** Each test case has a unique name (e.g., "chained", "forLoop") and a corresponding benchmark definition. These definitions are used to execute the JavaScript functions and measure their performance. **Latest Benchmark Result** The latest benchmark result is an array of objects that report the performance data for each test case: * `ExecutionsPerSecond`: The number of times the function was executed per second. * `RawUAString`: A string containing metadata about the browser and device used to execute the function (not relevant for this analysis). * `Browser`, `DevicePlatform`, and `OperatingSystem` are not relevant for this analysis. **What's Being Tested** The benchmark is testing the performance of three JavaScript functions: `chained()`, `forLoop()`, and `forLoop2()`. The test cases aim to evaluate how well each function performs in terms of execution frequency, which can be an important aspect of performance optimization in web development. Now, let's consider the implications of these results: * The `forLoop2()` test case has the highest execution frequency per second (203690.390625), indicating that it might be a more efficient implementation. * The `chained()` function performs poorly, with an execution frequency per second significantly lower than the other two functions. * The `forLoop()` function falls somewhere in between. This analysis suggests that the `forLoop2()` function is a good candidate for optimization or refactoring to improve its performance.
Related benchmarks:
TestsPerf2
foreach vs map by wayne
reduce vs plain cycle
Object Array update prop
Object Array update prop1
Comments
Confirm delete:
Do you really want to delete benchmark?