Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Redact an object
(version: 2)
Comparing performance of:
Array vs 1 by 1
Created:
3 years ago
by:
Registered User
Jump to the latest result
Tests:
Array
const testObject = { id: "1111", status: "active", mrr: 123, arr: [ 1, 2, 3, { n:[ {id: "a"}, {id: "b", status: "ee"} ] }, { status: "gg" } ], test: { id: "2222", status: "inactive", test2: { id: 3333, status: 3 } } }; function redactObject(obj, redactedKeys, newValue) { scanObject = (o) => { for (const [key, value] of Object.entries(o)) { redactedKeys.forEach(key => { if (o[key]) { o[key] = newValue } }); if (typeof value == "object") { scanObject(value); } } } scanObject(obj); } redactObject(testObject, ["status", "mrr"], "DELETED");
1 by 1
const testObject = { id: "1111", status: "active", mrr: 123, arr: [ 1, 2, 3, { n:[ {id: "a"}, {id: "b", status: "ee"} ] }, { status: "gg" } ], test: { id: "2222", status: "inactive", test2: { id: 3333, status: 3 } } }; function redactObject(obj, redactedKey, newValue) { scanObject = (o) => { for (const [key, value] of Object.entries(o)) { if (o[redactedKey]) { o[redactedKey] = newValue; } if (typeof value == "object") { scanObject(value); } } } scanObject(obj); } redactObject(testObject, "status", "DELETED"); redactObject(testObject, "mrr", "DELETED");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array
1 by 1
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 explain what's being tested, compared, and analyzed. **Benchmark Definition** The benchmark definition is a JSON object that provides metadata about the test case. In this case, it specifies: * `Name`: The name of the benchmark ("Redact an object") * `Description`: An empty string (not applicable) * `Script Preparation Code` and `Html Preparation Code`: Both are null (no setup or initializations required) **Individual Test Cases** There are two test cases: 1. **Array**: This test case uses a nested object with an array as a value. The script defines a function `redactObject` that recursively iterates over the object's properties and values, redacting specific keys by setting them to a new value (`"DELETED"`). 2. **1 by 1**: This test case is identical to the Array test case, but with a single iteration (instead of recursive). The script uses a similar `redactObject` function, but without the recursive loop. **Libraries and Special Features** There are no libraries mentioned in the benchmark definition or test cases. However, the `redactObject` function uses a closure to define an inner scope (`scanObject`) that iterates over properties and values using `Object.entries`. This is a standard JavaScript feature. **Options Compared** The two test cases differ only in how they iterate over the object's properties: 1. **Array**: Recursively iterates over all nested objects and arrays, using `Object.entries` to iterate over key-value pairs. 2. **1 by 1**: Iterates over each property individually (using the bracket notation `o[redactedKey]`) without recursion. **Pros and Cons of Each Approach** 1. **Array**: * Pros: Handles nested objects and arrays more thoroughly, which might be beneficial for complex data structures. * Cons: May be slower due to recursive iteration, as it needs to traverse all nested levels. 2. **1 by 1**: * Pros: More straightforward and potentially faster since it only iterates over individual properties without recursion. * Cons: Might not handle more complex or deeply nested data structures correctly. **Other Considerations** When evaluating these test cases, consider factors such as: * **Memory usage**: How much memory will the benchmark consume for each iteration? * **CPU utilization**: Will one approach be more CPU-intensive than the other? * **Data structure complexity**: Are there any specific edge cases or data structures that might affect performance? **Alternatives** If you were to design a similar benchmark, you could consider: 1. Adding additional test cases with different data structures (e.g., sets, maps) to further evaluate handling and performance. 2. Using different redaction values or scenarios to test the function's robustness. 3. Comparing performance using other programming languages or frameworks. Feel free to ask if there are any questions about this analysis!
Related benchmarks:
Object Deep Copy with jQuery
Object Deep Copy (+customs)
Is plain object
Object Deep Copy (+customs)(+customs)
Object Deep Copy 2024
Comments
Confirm delete:
Do you really want to delete benchmark?