Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Aaaaaaaaaaaaaa
(version: 0)
aads
Comparing performance of:
USando array vs Usando função find
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function generateUUID() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8; return v.toString(16); }); } var objectsArray = []; var itemsArray = []; const item = { "id": "72fdff2b-1fef-4d5a-944b-bf04e27ccd73", "title": "Teste", "type": "text", "tags": [] } const object = { "72fdff2b-1fef-4d5a-944b-bf04e27ccd73": { "title": "Teste", "type": "text", "tags": [] } } function generateItem() { return { id: generateUUID(), title: 'Teste', type: 'text', tags: [] }; } function generateObject() { let uuid = generateUUID(); return { [uuid]: { title: 'Teste', type: 'text', tags: [] } }; } // Gerar um array de objetos no formato JSON for (let i = 0; i < 100000; i++) { objectsArray.push(generateObject()); } objectsArray.push(object); for (let i = 0; i < 100000; i++) { itemsArray.push(generateItem()); } itemsArray.push(item);
Tests:
USando array
objectsArray["72fdff2b-1fef-4d5a-944b-bf04e27ccd73"]
Usando função find
itemsArray.find((menssage) => menssage.id === "72fdff2b-1fef-4d5a-944b-bf04e27ccd73")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
USando array
Usando função find
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
USando array
7886322.5 Ops/sec
Usando função find
341.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is being tested?** MeasureThat.net is testing the performance of two different methods for accessing and manipulating data in JavaScript: arrays and functions (specifically, the `find()` method). The benchmark defines two test cases: 1. "USando array" (Using Array): This test case accesses an element in the `objectsArray` using its index (`objectsArray["72fdff2b-1fef-4d5a-944b-bf04e27ccd73"]`). 2. "Usando função find" (Using Function Find): This test case uses the `find()` method to search for an element in the `itemsArray` that matches a specific condition (`itemsArray.find((menssage) => menssage.id === "72fdff2b-1fef-4d5a-944b-bf04e27ccd73")`). **Options compared** The benchmark is comparing two options: A. **Arrays**: This option uses direct array access to retrieve an element. B. **Function Find**: This option uses the `find()` method with a callback function to search for an element. **Pros and Cons of each approach** **Arrays** Pros: * Direct access, no overhead from function calls * Typically faster than function-based approaches Cons: * Limited flexibility and error handling capabilities * Can be brittle if data structure changes **Function Find** Pros: * More flexible and robust than direct array access * Easier to handle errors and edge cases Cons: * May incur additional overhead due to function calls * Can be slower than direct array access for large datasets **Other considerations** * The `find()` method is a part of the ECMAScript standard, making it a good choice for cross-browser compatibility. * The benchmark uses Chrome 124 as the browser, which may not represent other browsers' performance characteristics. **Library usage** The benchmark uses JavaScript built-in functions and data structures (arrays, objects), without relying on any external libraries. However, if we were to analyze the `find()` method's implementation, it relies on the ECMAScript standard and some internal function call optimizations. **Special JS features or syntax** There are no special JS features or syntax used in this benchmark that would be unfamiliar to software engineers with a basic understanding of JavaScript. The use of `find()` is a common pattern in JavaScript, and the rest of the code follows standard practices.
Related benchmarks:
object key vs indexof
Increment array with for( ... Object.Entries(...) ) vs Object.Entries(...).reduce
keys vs values
Object.values vs mapping id to object
Test spreads1
Comments
Confirm delete:
Do you really want to delete benchmark?