Skip to content

Object vs Dictionary #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
daiyam opened this issue Dec 23, 2016 · 5 comments
Closed

Object vs Dictionary #35

daiyam opened this issue Dec 23, 2016 · 5 comments

Comments

@daiyam
Copy link
Member

daiyam commented Dec 23, 2016

let foo = {} shouldn't add any instance methods (no toString())

Can't be replaced with Map due to performance but maybe with let foo = Object.create(null)
[source]

@daiyam
Copy link
Member Author

daiyam commented Jan 7, 2017

Object.create(null) has a performance impact over {}

bracket-0  x 50,340,464 ops/sec ±1.57% (80 runs sampled)
create-0   x  6,586,789 ops/sec ±1.16% (82 runs sampled)
bracket-10 x  1,962,417 ops/sec ±1.81% (85 runs sampled)
create-10  x  3,593,103 ops/sec ±1.41% (83 runs sampled)
bracket-50 x    527,150 ops/sec ±1.02% (87 runs sampled)
create-50  x    409,165 ops/sec ±1.66% (82 runs sampled)

@daiyam
Copy link
Member Author

daiyam commented Jan 7, 2017

var Empty = function () {};
Empty.prototype = Object.create(null);
bracket-0  x 51,518,693 ops/sec ±1.06% (83 runs sampled)
create-0   x  6,734,177 ops/sec ±0.72% (85 runs sampled)
empty-0    x 48,797,420 ops/sec ±0.90% (83 runs sampled)
bracket-10 x  1,998,575 ops/sec ±1.73% (85 runs sampled)
create-10  x  4,049,831 ops/sec ±1.75% (81 runs sampled)
empty-10   x  3,967,430 ops/sec ±1.42% (79 runs sampled)
bracket-50 x    527,756 ops/sec ±1.62% (84 runs sampled)
create-50  x    415,486 ops/sec ±1.63% (82 runs sampled)
empty-50   x    399,566 ops/sec ±1.18% (84 runs sampled)

@daiyam
Copy link
Member Author

daiyam commented Jan 8, 2017

33% performance hit under IE11

@daiyam
Copy link
Member Author

daiyam commented Aug 12, 2017

nodejs/node#11930

@daiyam
Copy link
Member Author

daiyam commented Sep 14, 2019

bracket-0 empty-0 reset-0 array-0 bracket-10 empty-10 reset-10 array-10 func-10 bracket-50 empty-50 reset-50 array-50
[email protected] 109,907,583 105,466,334 8,743,182 78,350,599 4,406,246 13,223,237 2,683,376 7,205,675 1,144,215 1,749,112 889,232 1,101,705
[email protected] 113,345,693 102,650,519 8,312,589 77,786,292 4,353,311 13,121,804 2,580,772 6,968,404 1,141,371 1,727,816 879,235 1,050,795
[email protected] 112,632,002 104,217,457 8,953,358 73,174,063 4,280,500 12,123,103 2,679,092 5,929,585 1,185,816 1,576,575 920,085 942,908
[email protected] 109,604,064 103,486,865 9,730,631 67,193,700 4,136,310 13,510,461 2,745,809 6,625,923 1,131,324 2,074,380 891,612 1,103,642
[email protected] 577,109,255 577,541,417 10,995,557 163,782,029 584,986,515 570,363,456 7,784,466 4,007,669 578,853,931 146,943,847 3,469,325 319,266
[email protected] 573,250,882 579,088,774 10,210,901 163,361,657 577,893,353 564,332,546 7,647,957 3,999,307 569,185,806 146,498,802 3,605,298 326,008
[email protected] 846,748,656 847,818,922 14,143,608 234,424,951 846,419,013 829,941,581 9,663,466 4,002,362 842,223,299 841,369,330 50,016,379 4,071,938 563,336
[email protected] 871,113,934 867,072,326 17,837,961 234,741,809 868,879,097 830,747,080 11,285,773 4,162,517 443,771,973 22,248,852 4,042,228 546,649
[email protected] 865,620,208 865,098,901 16,935,234 230,608,203 865,283,323 819,034,873 10,259,036 4,317,446 861,477,932 51,960,711 3,509,108 572,270
Chrome 40.0.2214 117,253,898 200,702,714 8,605,628 111,927,257 2,806,459 45,365,271 2,088,161 7,778,870 43,764,022
Chrome 50.0.2661 2,975,273 56,494,980 1,971,249 6,245,400
Chrome 76.0.3809 872,055,316 872,055,316 17,073,572 235,098,124 870,953,492 827,488,786 10,080,714 5,016,334 827,901,409 855,660,709 209,650,147 3,470,330 286,306
Firefox 47.0.0 1,573,406,353 11,870,567 3,633,647 5,737,666 1,637,340,851 15,805,276 4,189,813 287,772 13,917,884
Firefox 69.0.0 1,298,433,421 1,309,207,963 9,683,672 1,033,503,590 1,293,184,332 13,946,399 6,304,625 1,131,430 14,233,300 1,267,403,665 2,364,090 2,259,127 215,742
Safari 11.1.1 81,548,532 58,206,626 3,230,840 19,856,879 26,420,038 17,854,591 2,735,254 1,791,482 28,424,176 5,169,447 3,094,872 1,309,319 387,983
IE 11.0.0 22,430,695 14,677,008 586,672 548,016 12,904,876 7,702,810 6,155,842 326,736 103,459
0 n
[email protected] empty array
[email protected] empty array
[email protected] empty array
[email protected] empty array
[email protected] empty reset
[email protected] empty reset
[email protected] empty reset
[email protected] empty reset
[email protected] empty reset
Chrome 40.0.2214 empty array
Chrome 50.0.2661 empty array
Chrome 76.0.3809 empty reset
Firefox 47.0.0 empty reset
Firefox 69.0.0 empty reset
Safari 11.1.1 empty reset
IE 11.0.0 empty reset

@daiyam daiyam changed the title Object vs HashMap Object vs Dictionary Sep 21, 2019
@daiyam daiyam closed this as completed in 7a9f40d Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant