Skip to content

Latest commit

 

History

History
809 lines (597 loc) · 39.3 KB

RESULTS-v18.md

File metadata and controls

809 lines (597 loc) · 39.3 KB

Adding property

name ops/sec samples
Directly in the object 116,901,731 58453830
Using dot notation 74,760,492 37576596
Using define property (writable) 3,743,952 1872162
Using define property initialized (writable) 5,564,682 2782369
Using define property (getter) 2,091,801 1051458
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 16:42:31 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Array.append (number)

type amount time elapsed
array.push 10 0.011ms
new Array(length) 10 0.002ms
array.push 100 0.024ms
new Array(length) 100 0.009ms
array.push 1,000 0.037ms
new Array(length) 1,000 0.023ms
array.push 10,000 0.358ms
new Array(length) 10,000 0.154ms
array.push 1,000,000 27.225ms
new Array(length) 1,000,000 8.08ms
array.push 100,000,000 1,930.366ms
new Array(length) 100,000,000 4,026.761ms

Array.append (string)

type amount time elapsed
array.push 10 0.007ms
new Array(length) 10 0.018ms
array.push 100 0.013ms
new Array(length) 100 0.009ms
array.push 1,000 0.045ms
new Array(length) 1,000 0.026ms
array.push 10,000 0.45ms
new Array(length) 10,000 3.263ms
array.push 1,000,000 250.224ms
new Array(length) 1,000,000 4.544ms
array.push 100,000,000 2,303.42ms
new Array(length) 100,000,000 4,365.673ms

Array Creation

name ops/sec samples
new Array 254 128
Array.from 21 11
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 16:56:35 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Blob

name ops/sec samples
new Blob (128) 4,296 2149
new Blob (1024) 571 289
text (128) 48,218 24110
text (1024) 33,423 16716
arrayBuffer (128) 50,444 25223
arrayBuffer (1024) 30,535 15268
slice (0, 64) 76,395 38596
slice (0, 512) 30,884 15443
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:02:13 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Comparison using instanceof

name ops/sec samples
[True conditional] Using instanceof only 397,918 199393
[True conditional] Using constructor name 313,132 156709
[True conditional] Check if property is valid then instanceof 313,455 156732
[False conditional] Using instanceof only 44,431,341 22215679
[False conditional] Using constructor name 106,580,424 53294995
[False conditional] Check if property is valid then instanceof 106,633,487 53318170
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:07:50 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Crypto Verify

name ops/sec samples
crypto.createVerify('RSA-SHA256') 6,705 3353
crypto.verify('RSA-SHA256') 6,816 3409
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:13:53 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Date toISOString

name ops/sec samples
new Date().toISOString() 2,612,094 1306368
fromUnixToISOString(new Date()) 2,166,493 1083400
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:19:49 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Date format MM/DD/YYYY

name ops/sec samples
Intl.DateTimeFormat().format(Date.now()) 17,463 8733
Intl.DateTimeFormat().format(new Date()) 16,999 8688
Intl.DateTimeFormat(undefined, twoDigitsLocaleOptions).format(Date.now()) 18,452 9227
Intl.DateTimeFormat(undefined, twoDigitsLocaleOptions).format(new Date()) 18,111 9057
Reusing Intl.DateTimeFormat() 436,878 277606
Date.toLocaleDateString() 766,003 383004
Date.toLocaleDateString(undefined, twoDigitsLocaleOptions) 20,894 10448
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:24:57 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Date String coersion

name ops/sec samples
Using String() 967,173 484497
Using brackets {} 995,158 497580
Using '' + 982,123 491148
Using date.toString() 1,115,203 557668
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:31:46 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Deleting properties

name ops/sec samples
Using delete property 3,304,540 1652296
Using delete property (proto: null) 17,223,447 8612736
Using delete property (cached proto: null) 3,320,563 1660426
Using undefined assignment 81,586,723 40794271
Using undefined assignment (proto: null) 18,959,825 9480808
Using undefined property (cached proto: null) 81,248,447 40624226
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:36:45 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Node.js Error

name ops/sec samples
Error 380,995 190880
NodeError 298,123 149127
NodeError Range 305,191 152596
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:42:39 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Function return

name ops/sec samples
Function returning null 1,811,203 905924
Function returning explicitly undefined 1,784,775 893213
Function returning implicitly undefined 1,832,402 916294
Function returning string 1,827,705 913877
Function returning integer 1,867,870 933936
Function returning float 1,847,745 924136
Function returning functions 1,785,991 893079
Function returning arrow functions 1,828,574 914480
Function returning empty object 1,850,883 925443
Function returning empty array 1,859,734 929969
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:48:20 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Array.includes vs raw comparison

name ops/sec samples
using Array.includes 92,079,528 46046627
using Array.includes (first item) 85,065,128 42659254
Using raw comparison 103,394,962 51703142
Using raw comparison (first item) 106,518,331 53260569
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:54:13 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Object.keys vs Object.getOwnPropertyNames comparison

name ops/sec samples
Using Object.keys() 52,782,358 26392854
Using Object.getOwnPropertyNames() 44,914,504 22499229
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 17:59:59 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Get the last item of an Array

name ops/sec samples
Length = 100 - Array.at 23,494,059 11757016
Length = 10_000 - Array.at 20,987,781 10495476
Length = 1_000_000 - Array.at 21,379,868 10689937
Length = 100 - Array[length - 1] 102,240,074 51128837
Length = 10_000 - Array[length - 1] 102,778,160 51394349
Length = 1_000_000 - Array[length - 1] 102,693,697 51355552
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 18:05:26 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Math.floor vs ~

name ops/sec samples
Math.floor (small) 146,740,141 73370095
~ (small) 98,744,780 49372399
Math.floor (long) 105,171,463 52609556
~ (long) 106,802,917 53405557
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 18:11:13 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Object Creation

name ops/sec samples
Object.create(null) 47,181,346 23640051
Object.create({}) 1,302,053 664397
Cached Empty.prototype 122,985,092 61493478
Empty.prototype 1,445,231 736953
Empty class 916,018 469215
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 18:16:35 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Optional Chain (?) vs && operator

name ops/sec samples
Using optional chain (obj.field?.field2) (Valid) 151,966,213 76001582
Using optional chain (obj.field?.field2) (undefined) 102,557,318 51278772
Using and operator (obj.field && obj.field.field2) (Valid) 105,239,481 52619748
Using and operator (obj.field && obj.field.field2) (undefined) 104,440,721 52220371
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 18:22:40 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Parsing Integer

name ops/sec samples
Using parseInt(x, 10) - small number (2 len) 132,214,453 66107241
Using parseInt(x, 10) - big number (10 len) 17,222,411 8618478
Using + - small number (2 len) 104,781,265 52390642
Using + - big number (10 len) 106,028,083 53015910
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 18:28:20 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Possible undefined Function

name ops/sec samples
Using if to check function existence 691,107 345554
Using ? operator to avoid rejection 722,041 364030
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 18:34:33 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Private Property

name ops/sec samples
Raw usage private field 108,052,829 54035443
Raw usage underscore usage 82,847,571 41423793
Manipulating private properties using # 77,911,557 38959033
Manipulating private properties using underscore(_) 78,430,017 39215755
Manipulating private properties using Symbol 77,976,174 38988097
Manipulating private properties using PrivateSymbol 35,423,395 17712972
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 18:39:20 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Property access after shape transition

name ops/sec samples
Adding property after object creation - small object 3,699,971 1849987
Adding property in the object creation - small object 3,684,897 1842637
Adding property after the function creation - small class 183,760 92549
Adding property in the function creation - small class 186,232 93249
Adding property after the class creation - small class 161,824 80913
Adding property in the class creation - small class 158,094 79990
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 18:45:00 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Property Getter Access

name ops/sec samples
Getter (class) 155,158,595 77610478
Getter 54,242,943 27144097
Method 105,224,637 52612330
DefineProperty (getter) 105,701,299 52856282
DefineProperty (getter & enumerable=false) 55,091,185 27545870
DefineProperty (getter & configurable=false) 106,993,344 53510113
DefineProperty (getter & enumerable=false & configurable=false) 56,892,827 28450705
DefineProperty (writable) 106,690,400 53345208
DefineProperty (writable & enumerable=false) 105,608,026 52804027
DefineProperty (writable & enumerable=false & configurable=false) 92,978,699 46500369
DefineProperties (getter) 56,817,697 28410861
DefineProperties (getter & enumerable=false) 56,443,663 28221833
DefineProperties (getter & enumerable=false & configurable=false) 56,463,976 28232003
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 18:51:00 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Property Setter Access

name ops/sec samples
Setter (class) 146,141,577 73170739
Setter 10,486,251 5243130
Method 99,845,311 49952485
DefineProperty (setter) 104,861,274 52430647
DefineProperty (setter & enumerable=false) 10,578,873 5290320
DefineProperty (setter & configurable=false) 10,673,234 5339226
DefineProperty (setter & enumerable=false & configurable=false) 10,730,318 5367627
DefineProperty (writable) 100,270,298 50135293
DefineProperty (writable & enumerable=false) 101,071,806 50535914
DefineProperty (writable & enumerable=false & configurable=false) 99,941,747 49970920
DefineProperties (setter) 98,530,602 49266486
DefineProperties (setter & enumerable=false) 10,388,385 5194196
DefineProperties (setter & enumerable=false & configurable=false) 10,520,318 5260162
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 18:57:41 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

replace vs replaceAll comparison

name ops/sec samples
Using replace(//g) 3,334,259 1667504
Using replaceAll() 2,941,438 1470926
Using replaceAll(//g) 3,030,626 1515314
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 19:04:44 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Shallow Copy

name ops/sec samples
{ ...object } 20,580,595 10290308
{ ...object, proto: null } 19,821,049 9913160
{ ...object, newProp: true } 606,356 304381
structuredClone 250,854 125456
JSON.parse + JSON.stringify 199,343 99672
loop + object.keys starting with {} 1,283,426 641730
loop + object.keys starting with { proto: null } 754,789 377626
loop + object.keys starting with { randomProp: true } 525,945 263000
object.keys + reduce(FN, {}) 1,309,568 654911
object.keys + reduce(FN, { proto: null }) 756,896 378449
object.keys + reduce(FN, { newProp: true }) 530,831 265598
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 19:10:55 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Sorting Map

name ops/sec samples
Sort using default 263,973 131999
Sort using first char 1,260,604 634780
Sort using localeCompare 1,138,841 569561
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 19:16:46 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Object.assign VS spread operator

name ops/sec samples
{...bigObject} - Total keys: 1000 1,849 925
{...smallObject} - Total keys: 2 56,989,976 28500776
Object.assign({}, bigObject, anotherBigObject) - Total keys: 1000 - creating new object 1,087 544
Object.assign(bigObject, anotherBigObject) - mutating bigObject 6,221 3111
{ ...bigObject, ...anotherBigObject } 1,136 569
Object.assign({}, smallObject, anotherSmallObject) - creating new object 12,242,934 6124943
Object.assign(smallObject, anotherSmallObject) - mutating smallObject 28,046,211 14025608
{ ...smallObject, ...anotherSmallObject } 19,914,144 9957092
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 19:22:02 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Stream.Readable

name ops/sec samples
streams.Readable reading 1e3 * "some data" 2,235 1122
streams.web.Readable reading 1e3 * "some data" 604 303
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 19:28:27 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Stream.Writable

name ops/sec samples
streams.Writable writing 1e3 * "some data" 4,906 2454
streams.web.WritableStream writing 1e3 * "some data" 1,724 895
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 19:34:01 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

String concat

name ops/sec samples
Using + sign 161,162,184 80582393
Using backtick (`) 106,201,430 53100783
Using array.join 10,583,705 5293472
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 19:40:03 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

endsWith comparison

name ops/sec samples
(short string) (true) String#endsWith 61,916,283 31140279
(short string) (true) String#slice and strict comparison 48,746,891 24373452
(long string) (true) String#endsWith 50,208,440 25107274
(long string) (true) String#slice and strict comparison 44,645,634 22331724
(short string) (false) String#endsWith 57,961,816 28996495
(short string) (false) String#slice and strict comparison 59,502,057 29753313
(long string) (false) String#endsWith 55,107,162 27557563
(long string) (false) String#slice and strict comparison 51,870,572 25935306
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 19:45:46 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

String searching

name ops/sec samples
Using includes 154,305,542 77152812
Using indexof 15,858,142 7929225
Using RegExp.test 13,808,300 6912123
Using RegExp.text with cached regex pattern 14,704,721 7352363
Using new RegExp.test 4,378,841 2189573
Using new RegExp.test with cached regex pattern 4,940,824 2470647
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 19:51:12 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

startsWith comparison

name ops/sec samples
(short string) (true) String#startsWith 99,494,159 49844125
(short string) (true) String#slice and strict comparison 50,139,718 25073800
(long string) (true) String#startsWith 53,101,592 26550810
(long string) (true) String#slice and strict comparison 44,462,104 22234701
(short string) (false) String#startsWith 102,658,299 51334373
(short string) (false) String#slice and strict comparison 59,805,888 29903622
(long string) (false) String#startsWith 89,578,361 44789646
(long string) (false) String#slice and strict comparison 51,848,806 25924559
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 19:57:37 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Super vs This

name ops/sec samples
Using super 106,192,835 53102714
Using this 86,411,949 43205986
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 20:07:28 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4

Getting unix time

name ops/sec samples
new Date().getTime() 10,167,927 5084042
Date.now() 18,443,864 9221936
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Tue Oct 29 2024 20:12:43 GMT+0000 (Coordinated Universal Time)
  • Node: v18.20.4