Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
regex vs loop in keys
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser:
Chrome 124
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
regex
389265.2 Ops/sec
loop
373624.5 Ops/sec
Script Preparation code:
var ids = { "report_": "1", "index_": 1, "format_": 1, "random_": 1, "user_": 1, "data_": 1, "task_": 1, "event_": 1, "log_": 1, "note_": 1, "message_": 1, "notification_": 1, "order_": 1, "product_": 1, "transaction_": 1, "payment_": 1, "invoice_": 1, "customer_": 1, "account_": 1, "profile_": 1 };
Tests:
regex
var keys = [ "report_add", "report_test", "index_1234", "index_random", "format_example", "format_test", "random_abc", "random_123", "user_admin", "user_guest", "data_entry", "data_output", "task_todo", "task_done", "event_start", "event_end", "log_error", "log_warning", "note_personal", "note_public" ]; function getPureKey(key) { if (!key) { return ''; } return key.replace(/_\w+/g, '_'); } keys.forEach(function(k) { const key = getPureKey(k); const contains = ids[key]; });
loop
var keys = [ "report_add", "report_test", "index_1234", "index_random", "format_example", "format_test", "random_abc", "random_123", "user_admin", "user_guest", "data_entry", "data_output", "task_todo", "task_done", "event_start", "event_end", "log_error", "log_warning", "note_personal", "note_public" ]; function isCollectionMemberKey(collectionKey, key) { return key.startsWith(collectionKey) && key.length > collectionKey.length; } keys.forEach(function(k) { let contains = false; for (const collectionKey in ids) { if (isCollectionMemberKey(collectionKey, k)) { contains = true; } } });