Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
find the boss
(version: 0)
Comparing performance of:
old vs new filter first vs new sort first
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var encounters = { Argos: { name: "Argos", encounterNames: ["Argos"], }, ValtanG1: { name: "Valtan Gate 1", encounterNames: [ "Dark Mountain Predator", "Destroyer Lucas", "Leader Lugaru", ], }, ValtanG2: { name: "Valtan Gate 2", encounterNames: ["Demon Beast Commander Valtan"], }, VykasG1: { name: "Vykas Gate 1", encounterNames: ["Incubus Morphe", "Nightmarish Morphe"], }, VykasG2: { name: "Vykas Gate 2", encounterNames: ["Covetous Devourer Vykas"], }, VykasG3: { name: "Vykas Gate 3", encounterNames: ["Covetous Legion Commander Vykas"], }, KakulG1: { name: "Kakul-Saydon Gate 1", encounterNames: ["Saydon"], }, KakulG2: { name: "Kakul-Saydon Gate 2", encounterNames: ["Kakul"], }, KakulG3: { name: "Kakul-Saydon Gate 3", encounterNames: ["Kakul-Saydon"], }, BrelshazaG1: { name: "Brelshaza Gate 1", encounterNames: ["Gehenna Helkasirs"], }, BrelshazaG2: { name: "Brelshaza Gate 2", encounterNames: ["Prokel's Spiritual Echo", "Prokel"], }, BrelshazaG3: { name: "Brelshaza Gate 3", encounterNames: ["Ashtarot"], }, BrelshazaG4: { name: "Brelshaza Gate 4", encounterNames: ["Primordial Nightmare"], }, BrelshazaG5: { name: "Brelshaza Gate 5", encounterNames: ["Brelshaza, Monarch of Nightmares"], }, BrelshazaG6: { name: "Brelshaza Gate 6", encounterNames: ["Phantom Legion Commander Brelshaza"], }, /* GUARDIANS BELOW */ Achates: { name: "Achates", encounterNames: ["Achates", "Achates+"], }, Alberhastic: { name: "Alberhastic", encounterNames: ["Alberhastic", "Alberhastic+"], }, "Armored Nacrasena": { name: "Armored Nacrasena", encounterNames: ["Armored Nacrasena", "Armored Nacrasena+"], }, Caliligos: { name: "Caliligos", encounterNames: ["Caliligos"], }, Calventus: { name: "Calventus", encounterNames: ["Calventus", "Calventus+"], }, Chromanium: { name: "Chromanium", encounterNames: ["Chromanium", "Chromanium+"], }, "Dark Legoros": { name: "Dark Legoros", encounterNames: ["Dark Legoros", "Dark Legoros+"], }, Deskaluda: { name: "Deskaluda", encounterNames: ["Deskaluda", "Deskaluda+"], }, "Flame Fox Yoho": { name: "Flame Fox Yoho", encounterNames: ["Flame Fox Yoho", "Flame Fox Yoho+"], }, "Frost Helgaia": { name: "Frost Helgaia", encounterNames: ["Frost Helgaia", "Frost Helgaia+"], }, Helgaia: { name: "Helgaia", encounterNames: ["Helgaia", "Helgaia+"], }, "Icy Legoros": { name: "Icy Legoros", encounterNames: ["Icy Legoros", "Icy Legoros+"], }, Igrexion: { name: "Igrexion", encounterNames: ["Igrexion", "Igrexion+"], }, "Lava Chromanium": { name: "Lava Chromanium", encounterNames: ["Lava Chromanium", "Lava Chromanium+"], }, Levanos: { name: "Levanos", encounterNames: ["Levanos", "Levanos+"], }, Lumerus: { name: "Lumerus", encounterNames: ["Lumerus", "Lumerus+"], }, Nacrasena: { name: "Nacrasena", encounterNames: ["Nacrasena", "Nacrasena+"], }, "Night Fox Yoho": { name: "Night Fox Yoho", encounterNames: ["Night Fox Yoho", "Night Fox Yoho+"], }, Tytalos: { name: "Tytalos", encounterNames: ["Tytalos", "Tytalos+"], }, Urnil: { name: "Urnil", encounterNames: ["Urnil", "Ur'nil", "Urnil+"], }, Velganos: { name: "Velganos", encounterNames: ["Velganos", "Velganos+"], }, Vertus: { name: "Vertus", encounterNames: ["Vertus", "Vertus+"], }, Kungelanium: { name: "Kungelanium", encounterNames: ["Kungelanium", "Kungelanium+"], }, }; var randomProperty = function(obj) { var keys = Object.keys(obj); return obj[keys[keys.length * Math.random() << 0]]; }; const lookingFor = randomProperty(encounters).encounterNames[0]; var encounterNames = new Set(); for (let obj of Object.values(encounters)) { for (let name of obj.encounterNames) encounterNames.add(name); } var encNamesArray = Array.from(encounterNames); function makeid(length) { let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const charactersLength = characters.length; let counter = 0; while (counter < length) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); counter += 1; } return result; } function getRandomInt(max) { return Math.floor(Math.random() * max); } function getEncounter() { let encName = randomProperty(encounters).encounterNames[0]; return { name: encName, lastUpdate: getRandomInt(499128134), }; } // generate entities var entities = {}; for (let i = 0; i < 20; i++) { let name = makeid(8); let obj = { name: name, lastUpdate: getRandomInt(499128134), }; entities[name] = obj; } let enc = getEncounter(); entities[enc.name] = enc; for (let i = 0; i < 20; i++) { let name = makeid(8); let obj = { name: name, lastUpdate: getRandomInt(499128134), }; entities[name] = obj; } enc = getEncounter(); entities[enc.name] = enc; for (let i = 0; i < 20; i++) { let name = makeid(8); let obj = { name: name, lastUpdate: getRandomInt(499128134), }; entities[name] = obj; } enc = getEncounter(); entities[enc.name] = enc; for (let i = 0; i < 20; i++) { let name = makeid(8); let obj = { name: name, lastUpdate: getRandomInt(499128134), }; entities[name] = obj; } enc = getEncounter(); entities[enc.name] = enc; for (let i = 0; i < 20; i++) { let name = makeid(8); let obj = { name: name, lastUpdate: getRandomInt(499128134), }; entities[name] = obj; } enc = getEncounter(); entities[enc.name] = enc;
Tests:
old
if (entities) { const vals = Object.values(entities); if (vals.length > 0) { for (const entity of vals.sort( (a, b) => b.lastUpdate - a.lastUpdate )) { for (const encounter of Object.values(encounters)) { if (encounter.encounterNames.includes(entity.name)) { return; } } } } else { return; } }
new filter first
if (entities) { const vals = Object.values(entities).filter((el) => encounterNames.has(el.name)); if (vals.length > 0) { vals.sort( (a, b) => b.lastUpdate - a.lastUpdate ); let result = vals[0]; return; } else { return; } }
new sort first
if (entities) { const vals = Object.values(entities); vals.sort((a, b) => b.lastUpdate - a.lastUpdate); for (let val of vals) { if (encounterNames.has(val.name)) { let result = vals[0] return; } } } else { return; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
old
new filter first
new sort first
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):
It seems like you're describing a set of benchmarking results for different JavaScript code snippets related to filtering and sorting data in an object called `entities`. Given the benchmark results, it appears that: 1. The "old" filter-first approach is the slowest, with approximately 650 executions per second. 2. The "new filter first" approach is faster than the original but slower than the "new sort first" approach, with around 728 executions per second. 3. The "new sort first" approach is the fastest, with a relatively high number of executions per second (over 730). These results suggest that sorting the data first and then filtering it by name might be more efficient in this specific scenario. However, without knowing the exact code or context, it's difficult to provide a definitive conclusion. Would you like me to help with anything else?
Related benchmarks:
elielielieli
Native filter vs lodash find
lodash vs es6 in find method
sfdasdfsafdsfdsdf
sfdasdfsafdsfdsdfsdfg
Comments
Confirm delete:
Do you really want to delete benchmark?