Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
iterator memory test
(version: 0)
Comparing performance of:
iterator vs rows
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
text = ` Tue Aug 2 12:51:56.205 UTC ------------------------------------------------------------------------------- 0/0/CPU0 ------------------------------------------------------------------------------- Interface Address Version Refcount Protocol Gi0/0/0/0 (src mac only) 19 2( 0) ipv4 0000000000000200330011000800 mtu: 1500, flags 1 1 0 packets, 0 bytes Gi0/0/0/3.151 (src mac only) 32 2( 0) ipv4 000000000000020033001103810000970800 mtu: 1500, flags 1 1 0 packets, 0 bytes Gi0/0/0/3.157 10.33.157.112 71 2( 0) ipv4 0200330012030200330011038100009d0800 mtu: 1500, flags 1 0 0 packets, 0 bytes Gi0/0/0/2 10.33.129.110 35 2( 0) ipv4 001fca08e9970200330011020800 mtu: 1500, flags 1 0 341164 packets, 29461677 bytes Gi0/0/0/3.155 (src mac only) 28 2( 0) ipv4 0000000000000200330011038100009b0800 mtu: 1500, flags 1 1 0 packets, 0 bytes Gi0/0/0/0 10.33.131.112 63 2( 0) ipv4 0200330012000200330011000800 mtu: 1500, flags 1 0 106 packets, 21749 bytes Gi0/0/0/3.156 10.33.156.112 67 2( 0) ipv4 0200330012030200330011038100009c0800 mtu: 1500, flags 1 0 0 packets, 0 bytes Gi0/0/0/3.150 10.33.150.13 40 2( 0) ipv4 aabbcc82a400020033001103810000960800 mtu: 1500, flags 1 0 280344 packets, 15436343 bytes `; regex = /^\s*(?<nameOriginal>\S+)\s+\S+\s+(?:up|down)\s+(?:up|down)/i; namedRegex = /^\s*(?<nameOriginal>\S+)\s+\S+\s+(?:up|down)\s+(?:up|down)/gmi; keys = ['intL3Name', 'ip', 'mac'];
Tests:
iterator
const allMatchs = text.matchAll(namedRegex); for (const matchs of allMatchs) { console.log(matchs) for (let index = 0; index < keys.length; index ++) { let match = matchs[index + 1]; console.log(`key: ${key[index]}, match: ${match}`) } }
rows
const rows = text.split(/\n/); const result = rows.reduce((acc, row) => { const arrMatches = row.match(regex); if (arrMatches){ arrMatches.slice(1).forEach((v, index) => { console.log(`key: ${v}, index: ${index}`) }) } })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
iterator
rows
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'd be happy to help you understand the JavaScript microbenchmark on MeasureThat.net. **What is being tested?** The benchmark tests two approaches for parsing and processing data from a string: 1. **`iterator`**: This test uses a `matchAll()` method with a regular expression (`namedRegex`) to find all matches in the input string. The regex pattern looks for lines that start with a specific format, followed by some text, and then indicate whether the line is "up" or "down". The test then logs each match and extracts specific values from it. 2. **`rows`**: This test uses a `split()` method to split the input string into rows (separated by `\r\n`), and then applies another regular expression (`regex`) to each row to extract some values. The regex pattern is similar to the one used in the `iterator` test, but with a few differences. **Options compared** The two tests are comparing the performance of: * Using `matchAll()` versus `split()` as a way to process and extract data from strings. * How different approaches can affect performance, even when the underlying logic is similar. **Pros and Cons of each approach:** * **`iterator` (using `matchAll()`)**: + Pros: Can be more efficient for larger datasets or when specific values need to be extracted. + Cons: May be slower for smaller datasets or when exact matches are not necessary, as the regex engine needs to scan the entire string. * **`rows` (using `split()`)**: + Pros: Can be faster for smaller datasets or when exact matches are not necessary, as the `split()` method only scans a portion of the string. + Cons: May require more memory allocation and processing if the dataset is very large. **Library usage** Neither test uses any external libraries. However, it's worth noting that regex patterns (`namedRegex` and `regex`) might be considered part of a library or framework in some contexts. **Special JavaScript features** This benchmark doesn't use any special JavaScript features beyond regular expressions (regex). If you'd like to explore other features, I can try to help with that as well! **Other alternatives** Some alternative approaches for processing and extracting data from strings could include: * Using a parsing library or framework (e.g., `json` for parsing JSON) * Implementing custom parsing logic using loops and conditional statements * Using a streaming library or framework to process data in chunks These alternatives might offer different trade-offs between performance, readability, and complexity. If you have any specific questions about these alternatives or would like more information on the pros and cons of each approach, feel free to ask!
Related benchmarks:
FastStringMap test1
FastStringMap test2
FastStringMap test3
Buffer Access 4 - PK
modulo vs bitlogic
Comments
Confirm delete:
Do you really want to delete benchmark?