Skip to content

Latest commit

 

History

History
774 lines (562 loc) · 38.3 KB

RESULTS-v18.md

File metadata and controls

774 lines (562 loc) · 38.3 KB

Adding property

name ops/sec samples
Directly in the object 15,084,133 7542069
Using dot notation 14,829,183 7414592
Using define property (writable) 2,843,328 1421665
Using define property initialized (writable) 3,627,291 1813646
Using define property (getter) 1,776,545 888273
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 14:17:06 GMT+0000 (Coordinated Universal Time)

Array.append (number)

type amount time elapsed
array.push 10 0.01ms
new Array(length) 10 0.002ms
array.push 100 0.026ms
new Array(length) 100 0.01ms
array.push 1,000 0.042ms
new Array(length) 1,000 0.023ms
array.push 10,000 0.373ms
new Array(length) 10,000 0.139ms
array.push 1,000,000 25.492ms
new Array(length) 1,000,000 14.718ms
array.push 100,000,000 1,849.421ms
new Array(length) 100,000,000 4,115.064ms

Array.append (string)

type amount time elapsed
array.push 10 0.008ms
new Array(length) 10 0.018ms
array.push 100 0.015ms
new Array(length) 100 0.01ms
array.push 1,000 0.046ms
new Array(length) 1,000 0.026ms
array.push 10,000 0.458ms
new Array(length) 10,000 3.268ms
array.push 1,000,000 254.166ms
new Array(length) 1,000,000 4.601ms
array.push 100,000,000 2,302.592ms
new Array(length) 100,000,000 4,408.589ms

Array Creation

name ops/sec samples
new Array 272 137
Array.from 21 11
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 14:31:44 GMT+0000 (Coordinated Universal Time)

Blob

name ops/sec samples
new Blob (128) 4,388 2195
new Blob (1024) 534 268
text (128) 47,737 23869
text (1024) 29,674 14838
arrayBuffer (128) 50,162 25082
arrayBuffer (1024) 35,332 17667
slice (0, 64) 91,717 45859
slice (0, 512) 48,405 24371
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 14:36:01 GMT+0000 (Coordinated Universal Time)

Comparison using instanceof

name ops/sec samples
[True conditional] Using instanceof only 279,729 139865
[True conditional] Using constructor name 269,649 134825
[True conditional] Check if property is valid then instanceof 276,429 138215
[False conditional] Using instanceof only 11,350,843 5675422
[False conditional] Using constructor name 15,033,422 7516743
[False conditional] Check if property is valid then instanceof 15,138,404 7569203
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 14:44:30 GMT+0000 (Coordinated Universal Time)

Crypto Verify

name ops/sec samples
crypto.createVerify('RSA-SHA256') 7,192 3597
crypto.verify('RSA-SHA256') 7,166 3584
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 14:53:15 GMT+0000 (Coordinated Universal Time)

Date toISOString

name ops/sec samples
new Date().toISOString() 1,650,834 825418
fromUnixToISOString(new Date()) 1,830,227 915114
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 14:58:01 GMT+0000 (Coordinated Universal Time)

Date format MM/DD/YYYY

name ops/sec samples
Intl.DateTimeFormat().format(Date.now()) 17,260 8631
Intl.DateTimeFormat().format(new Date()) 19,856 9929
Intl.DateTimeFormat(undefined, twoDigitsLocaleOptions).format(Date.now()) 22,059 11030
Intl.DateTimeFormat(undefined, twoDigitsLocaleOptions).format(new Date()) 21,465 10733
Reusing Intl.DateTimeFormat() 669,220 334611
Date.toLocaleDateString() 692,390 346196
Date.toLocaleDateString(undefined, twoDigitsLocaleOptions) 21,350 10676
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 15:02:41 GMT+0000 (Coordinated Universal Time)

Date String coersion

name ops/sec samples
Using String() 824,028 412015
Using brackets {} 827,673 413837
Using '' + 828,466 414234
Using date.toString() 894,218 447110
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 15:09:40 GMT+0000 (Coordinated Universal Time)

Deleting properties

name ops/sec samples
Using delete property 2,600,844 1300423
Using delete property (proto: null) 7,875,765 3937883
Using delete property (cached proto: null) 2,536,225 1268113
Using undefined assignment 13,940,298 6970150
Using undefined assignment (proto: null) 8,589,785 4294893
Using undefined property (cached proto: null) 13,660,966 6830484
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 15:16:54 GMT+0000 (Coordinated Universal Time)

Node.js Error

name ops/sec samples
Error 271,434 135718
NodeError 268,981 134491
NodeError Range 267,818 133910
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 15:25:42 GMT+0000 (Coordinated Universal Time)

Function return

name ops/sec samples
Function returning null 1,497,800 748901
Function returning explicitly undefined 1,445,322 722662
Function returning implicitly undefined 1,569,513 784757
Function returning string 1,474,992 737497
Function returning integer 1,567,544 783773
Function returning float 1,533,048 766525
Function returning functions 1,514,842 757422
Function returning arrow functions 1,528,758 764380
Function returning empty object 1,539,782 769892
Function returning empty array 1,564,051 782026
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 15:32:02 GMT+0000 (Coordinated Universal Time)

Array.includes vs raw comparison

name ops/sec samples
using Array.includes 13,414,616 6707309
using Array.includes (first item) 14,044,827 7022414
Using raw comparison 15,388,859 7694430
Using raw comparison (first item) 15,248,783 7624392
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 15:40:45 GMT+0000 (Coordinated Universal Time)

Object.keys vs Object.getOwnPropertyNames comparison

name ops/sec samples
Using Object.keys() 12,771,082 6385542
Using Object.getOwnPropertyNames() 12,342,581 6171291
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 15:50:39 GMT+0000 (Coordinated Universal Time)

Get the last item of an Array

name ops/sec samples
Length = 100 - Array.at 8,560,644 4280323
Length = 10_000 - Array.at 8,600,756 4300379
Length = 1_000_000 - Array.at 8,563,489 4281745
Length = 100 - Array[length - 1] 15,133,383 7566692
Length = 10_000 - Array[length - 1] 15,215,981 7607991
Length = 1_000_000 - Array[length - 1] 14,952,804 7476403
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 15:57:36 GMT+0000 (Coordinated Universal Time)

Math.floor vs ~

name ops/sec samples
Math.floor (small) 14,697,149 7348575
~ (small) 15,285,317 7642659
Math.floor (long) 15,299,511 7649756
~ (long) 15,008,973 7504488
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 16:10:48 GMT+0000 (Coordinated Universal Time)

Object Creation

name ops/sec samples
Object.create(null) 12,121,536 6060769
Object.create({}) 1,223,103 611552
Cached Empty.prototype 14,632,609 7316305
Empty.prototype 1,327,053 663529
Empty class 884,492 442686
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 16:21:48 GMT+0000 (Coordinated Universal Time)

Optional Chain (?) vs && operator

name ops/sec samples
Using optional chain (obj.field?.field2) (Valid) 15,009,721 7504861
Using optional chain (obj.field?.field2) (undefined) 15,443,665 7721833
Using and operator (obj.field && obj.field.field2) (Valid) 15,211,068 7605535
Using and operator (obj.field && obj.field.field2) (undefined) 15,346,588 7673295
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 16:30:52 GMT+0000 (Coordinated Universal Time)

Parsing Integer

name ops/sec samples
Using parseInt(x, 10) - small number (2 len) 14,460,841 7230421
Using parseInt(x, 10) - big number (10 len) 7,784,290 3892146
Using + - small number (2 len) 14,884,168 7442085
Using + - big number (10 len) 14,755,956 7377979
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 16:41:36 GMT+0000 (Coordinated Universal Time)

Possible undefined Function

name ops/sec samples
Using if to check function existence 696,602 348302
Using ? operator to avoid rejection 705,520 352761
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 16:51:25 GMT+0000 (Coordinated Universal Time)

Private Property

name ops/sec samples
Raw usage private field 13,798,796 6899399
Raw usage underscore usage 14,246,621 7123311
Manipulating private properties using # 13,294,540 6647271
Manipulating private properties using underscore(_) 13,384,006 6692004
Manipulating private properties using Symbol 12,896,591 6448296
Manipulating private properties using PrivateSymbol 10,523,993 5261997
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 16:58:21 GMT+0000 (Coordinated Universal Time)

Property access after shape transition

name ops/sec samples
Adding property after object creation - small object 2,824,218 1412110
Adding property in the object creation - small object 2,833,602 1416802
Adding property after the function creation - small class 186,731 93367
Adding property in the function creation - small class 191,877 95939
Adding property after the class creation - small class 160,975 80488
Adding property in the class creation - small class 157,104 78553
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 17:10:10 GMT+0000 (Coordinated Universal Time)

Property Getter Access

name ops/sec samples
Getter (class) 14,665,104 7332553
Getter 12,416,532 6208267
Method 14,264,230 7132117
DefineProperty (getter) 14,533,199 7266600
DefineProperty (getter & enumerable=false) 12,421,318 6210660
DefineProperty (getter & configurable=false) 13,711,581 6855791
DefineProperty (getter & enumerable=false & configurable=false) 12,329,991 6164996
DefineProperty (writable) 13,837,469 6918735
DefineProperty (writable & enumerable=false) 14,055,065 7027533
DefineProperty (writable & enumerable=false & configurable=false) 13,740,445 6870223
DefineProperties (getter) 12,130,212 6065107
DefineProperties (getter & enumerable=false) 12,371,127 6185564
DefineProperties (getter & enumerable=false & configurable=false) 12,452,349 6226175
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 17:21:24 GMT+0000 (Coordinated Universal Time)

Property Setter Access

name ops/sec samples
Setter (class) 14,559,270 7279636
Setter 5,568,886 2784444
Method 14,390,458 7195230
DefineProperty (setter) 14,904,136 7452069
DefineProperty (setter & enumerable=false) 5,689,759 2844880
DefineProperty (setter & configurable=false) 5,673,674 2836838
DefineProperty (setter & enumerable=false & configurable=false) 5,651,142 2825572
DefineProperty (writable) 14,717,288 7358645
DefineProperty (writable & enumerable=false) 14,317,486 7158744
DefineProperty (writable & enumerable=false & configurable=false) 14,402,861 7201431
DefineProperties (setter) 14,230,525 7115263
DefineProperties (setter & enumerable=false) 5,637,517 2818759
DefineProperties (setter & enumerable=false & configurable=false) 5,655,134 2827568
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 17:41:27 GMT+0000 (Coordinated Universal Time)

replace vs replaceAll comparison

name ops/sec samples
Using replace(//g) 2,587,910 1293956
Using replaceAll() 2,352,344 1176173
Using replaceAll(//g) 2,324,996 1162499
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 18:01:19 GMT+0000 (Coordinated Universal Time)

Shallow Copy

name ops/sec samples
{ ...object } 8,818,913 4409457
{ ...object, proto: null } 8,924,831 4462416
{ ...object, newProp: true } 553,958 276980
structuredClone 247,124 123563
JSON.parse + JSON.stringify 196,426 98214
loop + object.keys starting with {} 1,120,305 560153
loop + object.keys starting with { proto: null } 666,195 333098
loop + object.keys starting with { randomProp: true } 485,881 242941
object.keys + reduce(FN, {}) 1,095,050 547526
object.keys + reduce(FN, { proto: null }) 620,419 310210
object.keys + reduce(FN, { newProp: true }) 479,589 239795
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 18:08:30 GMT+0000 (Coordinated Universal Time)

Sorting Map

name ops/sec samples
Sort using default 255,786 127894
Sort using first char 1,029,146 514574
Sort using localeCompare 924,813 462407
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 18:17:07 GMT+0000 (Coordinated Universal Time)

Object.assign VS spread operator

name ops/sec samples
{...bigObject} - Total keys: 1000 1,813 907
{...smallObject} - Total keys: 2 11,791,076 5895539
Object.assign({}, bigObject, anotherBigObject) - Total keys: 1000 - creating new object 2,157 1079
Object.assign(bigObject, anotherBigObject) - mutating bigObject 6,047 3024
{ ...bigObject, ...anotherBigObject } 1,087 544
Object.assign({}, smallObject, anotherSmallObject) - creating new object 6,248,364 3124183
Object.assign(smallObject, anotherSmallObject) - mutating smallObject 9,532,227 4766114
{ ...smallObject, ...anotherSmallObject } 8,093,122 4046562
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 18:23:18 GMT+0000 (Coordinated Universal Time)

Stream.Readable

name ops/sec samples
streams.Readable reading 1e3 * "some data" 2,335 1168
streams.web.Readable reading 1e3 * "some data" 613 307
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 18:32:24 GMT+0000 (Coordinated Universal Time)

Stream.Writable

name ops/sec samples
streams.Writable writing 1e3 * "some data" 4,906 2454
streams.web.WritableStream writing 1e3 * "some data" 2,080 1043
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 18:37:31 GMT+0000 (Coordinated Universal Time)

String concat

name ops/sec samples
Using + sign 14,828,167 7414084
Using backtick (`) 15,109,329 7554665
Using array.join 5,738,324 2869163
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 18:44:22 GMT+0000 (Coordinated Universal Time)

endsWith comparison

name ops/sec samples
(short string) (true) String#endsWith 12,045,954 6022978
(short string) (true) String#slice and strict comparison 12,081,236 6040619
(long string) (true) String#endsWith 11,739,042 5869522
(long string) (true) String#slice and strict comparison 11,837,242 5918622
(short string) (false) String#endsWith 12,079,039 6039520
(short string) (false) String#slice and strict comparison 12,483,546 6241774
(long string) (false) String#endsWith 12,141,296 6070649
(long string) (false) String#slice and strict comparison 12,163,741 6081871
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 18:53:25 GMT+0000 (Coordinated Universal Time)

String searching

name ops/sec samples
Using includes 8,313,526 4156764
Using indexof 8,292,643 4146322
Using RegExp.test 7,631,183 3815592
Using RegExp.text with cached regex pattern 7,740,790 3870396
Using new RegExp.test 3,177,946 1588974
Using new RegExp.test with cached regex pattern 3,509,829 1754915
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 19:09:17 GMT+0000 (Coordinated Universal Time)

startsWith comparison

name ops/sec samples
(short string) (true) String#startsWith 14,014,742 7007372
(short string) (true) String#slice and strict comparison 12,682,673 6341337
(long string) (true) String#startsWith 13,198,303 6599152
(long string) (true) String#slice and strict comparison 12,197,428 6098715
(short string) (false) String#startsWith 14,558,327 7279164
(short string) (false) String#slice and strict comparison 12,812,689 6406346
(long string) (false) String#startsWith 14,612,002 7306002
(long string) (false) String#slice and strict comparison 12,619,271 6309636
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 19:18:07 GMT+0000 (Coordinated Universal Time)

Super vs This

name ops/sec samples
Using super 14,236,132 7118067
Using this 14,604,368 7302185
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 19:34:37 GMT+0000 (Coordinated Universal Time)

Getting unix time

name ops/sec samples
new Date().getTime() 5,665,452 2832727
Date.now() 8,190,404 4095204
Environment
  • Machine: linux x64 | 4 vCPUs | 7.6GB Mem
  • Run: Mon Sep 02 2024 19:41:45 GMT+0000 (Coordinated Universal Time)