Skip to content

Latest commit

 

History

History
634 lines (464 loc) · 32.5 KB

RESULTS-v20.md

File metadata and controls

634 lines (464 loc) · 32.5 KB

Adding property

name ops/sec samples
Directly in the object 20,110,472 10055237
Using dot notation 20,097,786 10048894
Using define property (writable) 3,638,934 1819468
Using define property initialized (writable) 4,440,172 2220087
Using define property (getter) 2,251,893 1125947
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Mon May 13 2024 18:29:16 GMT+0000 (Coordinated Universal Time)

Array.append (number)

type amount time elapsed
array.push 10 0.004ms
new Array(length) 10 0.002ms
array.push 100 0.093ms
new Array(length) 100 0.008ms
array.push 1,000 0.033ms
new Array(length) 1,000 0.018ms
array.push 10,000 0.285ms
new Array(length) 10,000 0.328ms
array.push 1,000,000 32.258ms
new Array(length) 1,000,000 8.895ms
array.push 100,000,000 2,060.175ms
new Array(length) 100,000,000 4,690.918ms

Array.append (string)

type amount time elapsed
array.push 10 0.005ms
new Array(length) 10 0.003ms
array.push 100 0.011ms
new Array(length) 100 0.01ms
array.push 1,000 0.041ms
new Array(length) 1,000 0.021ms
array.push 10,000 0.235ms
new Array(length) 10,000 0.166ms
array.push 1,000,000 23.531ms
new Array(length) 1,000,000 4.68ms
array.push 100,000,000 2,827.857ms
new Array(length) 100,000,000 4,242.374ms

Array Creation

name ops/sec samples
new Array 231 116
Array.from 23 12
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Mon May 13 2024 18:51:37 GMT+0000 (Coordinated Universal Time)

Comparison using instanceof

name ops/sec samples
[True conditional] Using instanceof only 322,746 161374
[True conditional] Using constructor name 315,790 157896
[True conditional] Check if property is valid then instanceof 320,642 160322
[False conditional] Using instanceof only 19,872,338 9936170
[False conditional] Using constructor name 19,889,774 9944888
[False conditional] Check if property is valid then instanceof 19,877,970 9938986
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Mon May 13 2024 15:48:36 GMT+0000 (Coordinated Universal Time)

Crypto Verify

name ops/sec samples
crypto.createVerify('RSA-SHA256') 7,202 3602
crypto.verify('RSA-SHA256') 7,268 3635
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Mon May 13 2024 15:54:23 GMT+0000 (Coordinated Universal Time)

Date String coersion

name ops/sec samples
Using String() 1,044,430 522216
Using brackets {} 1,069,940 534971
Using '' + 1,065,282 532642
Using date.toString() 1,173,823 586912
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Mon May 13 2024 16:09:24 GMT+0000 (Coordinated Universal Time)

Deleting properties

name ops/sec samples
Using delete property 3,139,621 1569811
Using delete property (proto: null) 8,975,383 4487692
Using delete property (cached proto: null) 3,218,024 1609013
Using undefined assignment 19,998,313 9999157
Using undefined assignment (proto: null) 10,233,861 5116931
Using undefined property (cached proto: null) 19,977,183 9988592
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 21:21:49 GMT+0000 (Coordinated Universal Time)

Node.js Error

name ops/sec samples
Error 307,057 153529
NodeError 299,054 149528
NodeError Range 318,652 159327
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 21:28:36 GMT+0000 (Coordinated Universal Time)

Function return

name ops/sec samples
Function returning null 1,592,982 796492
Function returning explicitly undefined 1,586,970 793486
Function returning implicitly undefined 1,640,283 820142
Function returning string 1,595,506 797754
Function returning integer 1,626,137 813069
Function returning float 1,590,566 795284
Function returning functions 1,586,033 793017
Function returning arrow functions 1,596,911 798456
Function returning empty object 1,635,104 817553
Function returning empty array 1,622,077 811039
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 21:34:31 GMT+0000 (Coordinated Universal Time)

Array.includes vs raw comparison

name ops/sec samples
using Array.includes 19,893,651 9946826
using Array.includes (first item) 19,861,191 9930596
Using raw comparison 19,939,038 9969520
Using raw comparison (first item) 19,900,584 9950293
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 21:41:37 GMT+0000 (Coordinated Universal Time)

Object.keys vs Object.getOwnPropertyNames comparison

name ops/sec samples
Using Object.keys() 16,959,154 8479578
Using Object.getOwnPropertyNames() 16,361,323 8180662
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 21:49:16 GMT+0000 (Coordinated Universal Time)

Get the last item of an Array

name ops/sec samples
Length = 100 - Array.at 19,669,322 9834662
Length = 10_000 - Array.at 19,712,321 9856161
Length = 1_000_000 - Array.at 19,805,707 9902854
Length = 100 - Array[length - 1] 19,834,283 9917142
Length = 10_000 - Array[length - 1] 19,887,730 9943866
Length = 1_000_000 - Array[length - 1] 19,919,314 9959658
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 21:56:57 GMT+0000 (Coordinated Universal Time)

Object Creation

name ops/sec samples
Object.create(null) 14,411,793 7205897
Object.create({}) 1,878,343 939175
Cached Empty.prototype 19,824,384 9912193
Empty.prototype 1,921,634 960818
Empty class 1,280,617 640309
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 22:04:21 GMT+0000 (Coordinated Universal Time)

Optional Chain (?) vs && operator

name ops/sec samples
Using optional chain (obj.field?.field2) (Valid) 19,915,677 9957839
Using optional chain (obj.field?.field2) (undefined) 19,970,257 9985129
Using and operator (obj.field && obj.field.field2) (Valid) 19,706,199 9853100
Using and operator (obj.field && obj.field.field2) (undefined) 18,557,016 9278509
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 22:13:52 GMT+0000 (Coordinated Universal Time)

Parsing Integer

name ops/sec samples
Using parseInt(x, 10) - small number (2 len) 19,964,712 9982357
Using parseInt(x, 10) - big number (10 len) 19,951,021 9975511
Using + - small number (2 len) 20,022,968 10011485
Using + - big number (10 len) 19,943,938 9971970
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 22:21:49 GMT+0000 (Coordinated Universal Time)

Possible undefined Function

name ops/sec samples
Using if to check function existence 1,086,195 543099
Using ? operator to avoid rejection 1,077,741 538871
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 22:27:36 GMT+0000 (Coordinated Universal Time)

Private Property

name ops/sec samples
Raw usage private field 19,850,729 9925366
Raw usage underscore usage 19,872,382 9936192
Manipulating private properties using # 19,921,033 9960517
Manipulating private properties using underscore(_) 19,883,151 9941576
Manipulating private properties using Symbol 19,924,133 9962067
Manipulating private properties using PrivateSymbol 14,887,271 7443636
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 22:34:52 GMT+0000 (Coordinated Universal Time)

Property access after shape transition

name ops/sec samples
Adding property after object creation - small object 3,970,323 1985162
Adding property in the object creation - small object 4,054,408 2027205
Adding property after the function creation - small class 275,167 137585
Adding property in the function creation - small class 265,748 132875
Adding property after the class creation - small class 268,473 134237
Adding property in the class creation - small class 268,565 134283
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 22:41:47 GMT+0000 (Coordinated Universal Time)

Property Getter Access

name ops/sec samples
Getter (class) 19,893,449 9946725
Getter 16,031,760 8015881
Method 19,864,551 9932276
DefineProperty (getter) 19,974,259 9987130
DefineProperty (getter & enumerable=false) 16,125,119 8062560
DefineProperty (getter & configurable=false) 19,983,139 9991570
DefineProperty (getter & enumerable=false & configurable=false) 15,970,091 7985046
DefineProperty (writable) 20,001,298 10000650
DefineProperty (writable & enumerable=false) 19,966,973 9983487
DefineProperty (writable & enumerable=false & configurable=false) 19,940,209 9970105
DefineProperties (getter) 16,234,319 8117160
DefineProperties (getter & enumerable=false) 16,433,660 8216831
DefineProperties (getter & enumerable=false & configurable=false) 16,159,406 8079704
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 22:52:43 GMT+0000 (Coordinated Universal Time)

Property Setter Access

name ops/sec samples
Setter (class) 19,258,319 9629160
Setter 6,821,833 3410917
Method 19,183,680 9591841
DefineProperty (setter) 19,226,153 9613077
DefineProperty (setter & enumerable=false) 6,783,336 3391669
DefineProperty (setter & configurable=false) 6,737,434 3368718
DefineProperty (setter & enumerable=false & configurable=false) 6,864,497 3432249
DefineProperty (writable) 19,192,946 9596474
DefineProperty (writable & enumerable=false) 19,154,430 9577216
DefineProperty (writable & enumerable=false & configurable=false) 19,190,671 9595336
DefineProperties (setter) 19,183,323 9591662
DefineProperties (setter & enumerable=false) 6,920,356 3460179
DefineProperties (setter & enumerable=false & configurable=false) 6,954,774 3477388
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 23:11:12 GMT+0000 (Coordinated Universal Time)

Shallow Copy

name ops/sec samples
{ ...object } 11,679,046 5839524
{ ...object, proto: null } 10,838,698 5419353
{ ...object, newProp: true } 869,467 434734
structuredClone 301,381 150691
JSON.parse + JSON.stringify 186,719 93363
loop + object.keys starting with {} 1,416,953 708477
loop + object.keys starting with { proto: null } 857,825 428913
loop + object.keys starting with { randomProp: true } 636,536 318269
object.keys + reduce(FN, {}) 1,449,664 724833
object.keys + reduce(FN, { proto: null }) 824,315 412158
object.keys + reduce(FN, { newProp: true }) 648,508 324255
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 23:25:26 GMT+0000 (Coordinated Universal Time)

Sorting Map

name ops/sec samples
Sort using default 262,762 131382
Sort using first char 1,326,742 663372
Sort using localeCompare 1,255,138 627570
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 23:33:22 GMT+0000 (Coordinated Universal Time)

Object.assign VS spread operator

name ops/sec samples
{...bigObject} - Total keys: 1000 2,283 1142
{...smallObject} - Total keys: 2 15,399,434 7699718
Object.assign({}, bigObject, anotherBigObject) - Total keys: 1000 - creating new object 2,539 1270
Object.assign(bigObject, anotherBigObject) - mutating bigObject 6,798 3400
{ ...bigObject, ...anotherBigObject } 1,373 687
Object.assign({}, smallObject, anotherSmallObject) - creating new object 7,746,286 3873144
Object.assign(smallObject, anotherSmallObject) - mutating smallObject 12,923,066 6461534
{ ...smallObject, ...anotherSmallObject } 11,314,583 5657293
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Thu May 09 2024 23:41:33 GMT+0000 (Coordinated Universal Time)

String concat

name ops/sec samples
Using + sign 20,007,746 10003874
Using backtick (`) 20,011,079 10005540
Using array.join 6,878,505 3439253
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Fri May 10 2024 00:01:03 GMT+0000 (Coordinated Universal Time)

endsWith comparison

name ops/sec samples
(short string) (true) String#endsWith 16,120,285 8060143
(short string) (true) String#slice and strict comparison 20,050,319 10025160
(long string) (true) String#endsWith 15,731,196 7865599
(long string) (true) String#slice and strict comparison 19,945,290 9972646
(short string) (false) String#endsWith 16,301,679 8150840
(short string) (false) String#slice and strict comparison 19,998,911 9999456
(long string) (false) String#endsWith 16,194,333 8097167
(long string) (false) String#slice and strict comparison 19,339,169 9669585
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Fri May 10 2024 00:10:31 GMT+0000 (Coordinated Universal Time)

String searching

name ops/sec samples
Using includes 19,661,785 9830893
Using indexof 19,687,397 9843699
Using RegExp.test 9,245,646 4622824
Using RegExp.text with cached regex pattern 9,407,774 4703888
Using new RegExp.test 3,658,511 1829256
Using new RegExp.test with cached regex pattern 4,137,490 2068746
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Fri May 10 2024 00:22:10 GMT+0000 (Coordinated Universal Time)

startsWith comparison

name ops/sec samples
(short string) (true) String#startsWith 18,409,141 9204572
(short string) (true) String#slice and strict comparison 19,923,796 9961899
(long string) (true) String#startsWith 17,619,568 8809785
(long string) (true) String#slice and strict comparison 19,985,623 9992812
(short string) (false) String#startsWith 19,505,805 9752903
(short string) (false) String#slice and strict comparison 19,955,970 9977986
(long string) (false) String#startsWith 19,160,563 9580282
(long string) (false) String#slice and strict comparison 19,818,590 9909296
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Fri May 10 2024 00:30:41 GMT+0000 (Coordinated Universal Time)

Super vs This

name ops/sec samples
Using super 19,251,118 9625560
Using this 19,430,616 9715309
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Fri May 10 2024 00:39:26 GMT+0000 (Coordinated Universal Time)

Getting unix time

name ops/sec samples
new Date().getTime() 7,154,543 3577272
Date.now() 10,240,664 5120333
Environment
  • Machine: linux x64 | 4 vCPUs | 15.2GB Mem
  • Run: Fri May 10 2024 00:46:05 GMT+0000 (Coordinated Universal Time)