Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Avoid repeating operations
(version: 3)
Comparing performance of:
Without cashing the operation vs Cashing the operation
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var ICON_TO_FACILITY_ID = { parking_sign: [2, 46, 160, 161, 162, 179, 180, 181], food_and_drink: [3, 6, 115, 116, 176, 177, 306, 409, 9103, 9114, 9115], pawprint: [4, 217, 218], clean: [5, 158], bar: [7, 199], frontdesk: [8, 78, 418], tennis: [9, 87, 215, 216], sauna: [10, 79], fitness: [11, 253, 255, 256], golf: [12, 97], newspapers: [13], garden: [14], resort: [15, 118, 222], nosmoking: [16, 108], shuttle: [17, 128, 139, 209, 210, 304, 430], fish: [19], briefcase: [20], baby_bottle: [21], washer: [22, 23, 429], coffee: [24, 43, 219, 305], disabled: [25, 184, 185, 186, 187, 188, 189], skiing: [26, 100, 130, 131, 132], salon: [27, 230, 233, 234, 235], family: [28], game: [29], playing_cards: [30], crown: [41], iron: [44], wifi: [47, 96, 107, 163, 164], elevator: [48], instantconf: [49], solarium: [50], safe: [51], valet_parking: [52], change_currency: [53], spa: [54, 227, 228, 236, 237, 238, 239, 240, 242, 243, 244], massage: [55, 245, 246, 247, 248, 249, 250, 251, 252], billiard_ball: [57], music_note: [59, 126, 147, 410], shopping_bag: [60, 81, 92], windsurfing: [61], spring: [63, 138, 166, 167, 241], soundproof: [64], bike_fee: [65], book: [66, 171], sparkles: [67, 101], canoe: [69], hiking: [70, 404], cathedral: [71], bbq: [72], packed_lunch: [73, 224], car_side: [75], bike: [76, 123, 405, 426], bowling: [77], heater: [80], diving: [82, 90], horse: [86], taxi: [89], cabin_trolley: [91], luggage_storage: [99], pool: [ 103, 104, 119, 120, 121, 122, 148, 169, 192, 193, 194, 195, 196, 197, 198, 200, 201, 223, 258, 301, 433 ], snowflake: [109], smoking: [110], atm: [111], beach: [114, 146, 220, 221, 302, 9000], breakfast: [117, 9104, 9105, 9106, 9107, 9108, 9109, 9110, 9111, 9112, 9113], concierge: [124], sunglasses: [127, 168], shuttle_fee: [129, 140], page: [133], vending_machine: [135, 136], kitesurfing: [137], oven: [141], key: [142, 257, 419, 420], couch: [143], basket: [145], person: [149], shopping_cart: [159], screen: [175], flash: [182], bus_side: [183], wine: [203, 407], grapes: [205], waffle: [206], attractions: [207], visual_impairment: [211, 212], stroller: [214], campfire: [225], makeup: [226, 229, 231, 232], yoga: [254], paintbrush: [400], beer: [401], theater: [402], play: [403], geo_pin_heart: [408], megaphone: [421, 422], videochat: [423, 424], wind: [425], phone: [427], email: [428], bath: [431], checkin: [8001], checkout: [8002] }; var getFacilityIconById1 = facilityId => { for (var icon in ICON_TO_FACILITY_ID) { if (ICON_TO_FACILITY_ID[icon].indexOf(facilityId) !== -1) { return icon; } } return 'checkmark'; }; var getFacilityIconById2 = (() => { var hash; return (facilityId) => { if (!hash) { hash = Object.entries(ICON_TO_FACILITY_ID).reduce((obj, item) => { item[1].forEach(id => obj[id] = item[0]); return obj; }, {}); } return hash[facilityId] || 'checkmark'; }; })();
Tests:
Without cashing the operation
for (var i = 0; i < 10000; i++) { getFacilityIconById1(i); }
Cashing the operation
for (var i = 0; i < 10000; i++) { getFacilityIconById2(i); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Without cashing the operation
Cashing the operation
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):
The provided code is written in JavaScript, and it appears to be a benchmarking script for comparing the performance of two functions: `getFacilityIconById1` and `getFacilityIconById2`. Here's a breakdown of what each part does: **ICON_TO_FACILITY_ID Object** ```javascript const ICON_TO_FACILITY_ID = { // object with facility IDs as keys and icon names as values }; ``` This object maps facility IDs to their corresponding icon names. **getFacilityIconById1 Function** ```javascript var getFacilityIconById1 = facilityId => { for (var icon in ICON_TO_FACILITY_ID) { if (ICON_TO_FACILITY_ID[icon].indexOf(facilityId) !== -1) { return icon; } } return 'checkmark'; }; ``` This function iterates through the `ICON_TO_FACILITY_ID` object and checks if the provided `facilityId` is present in any of the icon names. If found, it returns the corresponding icon name. **getFacilityIconById2 Function ( cached version )** ```javascript var getFacilityIconById2 = (() => { var hash; return (facilityId) => { if (!hash) { hash = Object.entries(ICON_TO_FACILITY_ID).reduce((obj, item) => { item[1].forEach(id => obj[id] = item[0]); return obj; }, {}); } return hash[facilityId] || 'checkmark'; }; })(); ``` This function uses a cached version of the `getFacilityIconById1` logic by creating a hash object from the `ICON_TO_FACILITY_ID` object. This allows for faster lookups without iterating through the entire object. **Benchmarking** ```javascript [ { "Benchmark Definition": "for (var i = 0; i < 10000; i++) {\r\n getFacilityIconById1(i);\r\n}", "Test Name": "Without cashing the operation" }, { "Benchmark Definition": "for (var i = 0; i < 10000; i++) {\r\n getFacilityIconById2(i);\r\n}", "Test Name": "Cashing the operation" } ] ``` This is an array of benchmarking configurations, with two test cases: 1. Without caching the operation (using `getFacilityIconById1`) 2. With caching the operation (using `getFacilityIconById2`) The benchmarking results will compare the execution speeds of these two functions for a large number of iterations. Please note that I'm assuming this is an actual code snippet, but it appears to be incomplete or modified for demonstration purposes. If you need help with actual debugging or optimization, feel free to provide more context!
Related benchmarks:
Vanilla vs Lodash
Map, filter, reduce, intersection comparison
Map, filter, concat, intersection comparison
Group by single pass vs multiple
makes fast
Comments
Confirm delete:
Do you really want to delete benchmark?