Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs WeakMap
(version: 5)
Comparing performance of:
Map vs WeakMap
Created:
5 months ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const getInt = (()=>{r=Math.random;f=Math.floor;return (a=0,b=0x100000000)=>f(r()*(b-a))+a})(); const getStr = (()=>{ const f = (n)=> n < 10 ? 0x30 + n : n < 36 ? 0x41 + (n - 10) : 0x61 + (n - 36); return (n)=> String.fromCharCode(...(new Int32Array(n)).map(()=>f(getInt(0,62)))); })(); const keys = []; const N = 0x40000; const map = new Map(); const weakmap = new WeakMap(); for(i=0;i<N;i++){ let key = {i}; let value = getInt(); map.set(key,value); weakmap.set(key,value); keys[i] = key; }
Tests:
Map
var a = map.get(keys[getInt(0,N)]);
WeakMap
var a = weakmap.get(keys[getInt(0,N)]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map
WeakMap
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Map
168248128.0 Ops/sec
WeakMap
167431136.0 Ops/sec
Related benchmarks:
Object vs Map
Map vs Object 12345
Object vs Map 5
Map vs Object with 100 keys
Map vs Object with 100 keys and mutate
Map vs Object with 100 keys and 1/2 delete
Member Access Object vs Map(string key) vs Map(object key)
Unique Instance Test
Temp Test
Comments
Confirm delete:
Do you really want to delete benchmark?