Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
String manipulation vs
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
Strings manipulation
116118.0 Ops/sec
using Objects
357042.1 Ops/sec
Script Preparation code:
var stringIds = [ "report_123", "report_33", "index_1234", "index_5678", "users_", "details_2", "isOpen", "report_45", "report_678", "index_90", "users_12", "details_", "isOpen_56", "report_789", "report_", "index_111", "users_22", "details_33", "isOpen", "report_555", "report_999", "index_1000", "users_200", "details_300", "isOpen", "report_88", "report_", "index_66", "users_55", "details_44", "isOpen", "report_11", "report_22", "index_33", "users_44", "details_55", "isOpen", "report_100", "report_200", "index_300" ]; var collections = [ { collectionKey: "report_", item: "123" }, { collectionKey: "users_", item: "" }, { collectionKey: "index_", item: "5678" }, { collectionKey: "report_", item: "" }, { collectionKey: "details_", item: "222" }, { collectionKey: "isOpen_", item: "101" }, { collectionKey: "report_", item: "" }, { collectionKey: "users_", item: "678" }, { collectionKey: "details_", item: "4445" }, { collectionKey: "index_", item: "90" }, { collectionKey: "index_", item: "90233" }, { collectionKey: "details_", item: "300" }, { collectionKey: "isOpen_", item: "555" }, { collectionKey: "report_", item: "789" }, { collectionKey: "report_", item: "" }, { collectionKey: "report_", item: "" }, { collectionKey: "report_", item: "" }, { collectionKey: "report_", item: "" }, { collectionKey: "users_", item: "11" }, { collectionKey: "index_", item: "222" }, { key: "isOpen" }, { key: "hasInternet" }, { key: "hasInternet" }, { key: "hasInternet" }, { key: "hasInternet" }, { key: "hasInternet" }, { key: "hasInternet" }, { key: "hasInternet" }, { key: "hasInternet" }, { key: "details" }, { key: "isClosed" }, { key: "hasError" }, { key: "isLoaded" }, { key: "isValid" }, { key: "hasData" }, { key: "isVisible" }, { key: "isEnabled" }, { key: "hasAccess" }, { key: "isAdmin" }, { key: "isOnline" } ];
Tests:
Strings manipulation
const cache = { "report_123": [1], "report_33": [2], "index_1234": [3], "index_5678": [4], "users_": [5], "details_2": [6], "isOpen": [34], "report_678": [8], "index_": [9], "users_12": [10], "details_": [11], "report_789": [12], "index_111": [14], "users_22": [15], "details_33": [16], "report_555": [17], "report_999": [18], "index_1000": [19], "users_200": [20], "details_300": [21], "report_88": [22], "index_66": [23], "users_55": [24], "details_44": [25], "report_11": [26], "report_22": [27], "index_33": [28], "users_44": [29], "details_55": [30], "report_100": [31], "report_": [32, 7, 13], "index_300": [33], "isOpen": [36], }; function splitCollectionMemberKey(key) { const underscoreIndex = key.indexOf('_'); if (underscoreIndex === -1) { return []; } return [key.substring(0, underscoreIndex + 1), key.substring(underscoreIndex + 1)]; } function isCollectionMemberKey(collectionKey, key) { return key.startsWith(collectionKey) && key.length > collectionKey.length; } function getCollectionKey(key) { if (!key) { return ''; } return key.replace(/_\w+/g, '_'); } function keyChanged(key) { let stateMappingKeys = cache[key] ?? []; const collectionKey = getCollectionKey(key); const plainCollectionKey = collectionKey.lastIndexOf('_') !== -1 ? collectionKey : undefined; if (plainCollectionKey) { // Getting the collection key from the specific key because only collection keys were stored in the mapping. stateMappingKeys = [...stateMappingKeys, ...(cache[plainCollectionKey] ?? [])]; } const collectionWithValue = splitCollectionMemberKey(key); } stringIds.forEach((k) => keyChanged(k));
using Objects
const cache = { "isOpen": [1], "hasInternet": [2], "hasInternet": [3], "hasInternet": [4], "hasInternet": [5], "hasInternet": [6], "hasInternet": [7], "hasInternet": [8], "hasInternet": [9], "details": [10], "isClosed": [11], "hasError": [12], "isLoaded": [13], "isValid": [14], "hasData": [15], "isVisible": [16 ], "isEnabled": [17], "hasAccess": [18], "isAdmin": [19], "isOnline": [2], "report_123": [100], "users_": [101], "index_5678": [102], "details_222": [104], "isOpen_101": [105], "users_678": [107], "details_4445": [108], "index_90": [109], "index_90233": [200], "details_300": [201], "isOpen_555": [202], "report_789": [203], "report_": [103, 106, 204, 205, 206, 207], "users_11": [208], "index_222": [209] }; function normalizeConnection(mapping) { if (mapping.collectionKey) { mapping.isCollection = true; mapping.isRoot = mapping.item.length === 0; } else { mapping.isCollection = false; } return mapping; } const finalKeys = collections.map((k) => normalizeConnection(k)); function keyChanged(mapping) { const key = mapping.isCollection ? `${mapping.collectionKey}${mapping.item}` : mapping.key; let stateMappingKeys = cache[key] ?? []; if (mapping.isRoot) { // Getting the collection key from the specific key because only collection keys were stored in the mapping. stateMappingKeys = [...stateMappingKeys, ...(cache[mapping.collectionKey] ?? [])]; } const collectionWithValue = [mapping.collectionKey, mapping.item]; } finalKeys.forEach((k) => keyChanged(k));