Skip to content

Commit

Permalink
update: cleanup benchmark files
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS committed Nov 23, 2024
1 parent 82ef713 commit a1bc662
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 178 deletions.
49 changes: 0 additions & 49 deletions bench/compare-using-instanceof.mjs

This file was deleted.

57 changes: 0 additions & 57 deletions bench/function-return.mjs

This file was deleted.

6 changes: 3 additions & 3 deletions bench/last-array-item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const suite = createBenchmarkSuite('Get the last item of an Array')

const arr100 = Array.from({ length: 100 }, () => Math.floor(Math.random() * 100))
const arr10_000 = Array.from({ length: 10000 }, () => Math.floor(Math.random() * 100))
const arr100_000_0 = Array.from({ length: 1000000 }, () => Math.floor(Math.random() * 100))
const arr1_000_000 = Array.from({ length: 1000000 }, () => Math.floor(Math.random() * 100))

suite
.add('Length = 100 - Array.at', function () {
Expand All @@ -14,7 +14,7 @@ suite
return arr10_000.at(-1)
})
.add('Length = 1_000_000 - Array.at', function () {
return arr100_000_0.at(-1)
return arr1_000_000.at(-1)
})
.add('Length = 100 - Array[length - 1]', function () {
return arr100[arr100.length - 1]
Expand All @@ -23,7 +23,7 @@ suite
return arr10_000[arr10_000.length - 1]
})
.add('Length = 1_000_000 - Array[length - 1]', function () {
return arr100_000_0[arr100_000_0.length - 1]
return arr1_000_000[arr1_000_000.length - 1]
})

await suite.runAndPrintResults()
18 changes: 8 additions & 10 deletions bench/object-creation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { createBenchmarkSuite } from '../common.mjs'

const suite = createBenchmarkSuite('Object Creation')

function Empty() {}
Empty.prototype = Object.create(null)
function EmptyPrototype() {}
EmptyPrototype.prototype = Object.create(null)

class C {
constructor () {}
}

suite
.add('Object.create(null)', function () {
Expand All @@ -12,16 +16,10 @@ suite
.add('Object.create({})', function () {
return Object.create({})
})
.add('Cached Empty.prototype', function () {
return new Empty()
})
.add('Empty.prototype', function () {
function NE() {}
NE.prototype = Object.create(null)
return new NE()
.add('new Function with empty prototype', function () {
return new EmptyPrototype()
})
.add('Empty class', function () {
function C() {}
return new C()
})

Expand Down
31 changes: 0 additions & 31 deletions bench/optional-chain-vs-and-operator.mjs

This file was deleted.

28 changes: 0 additions & 28 deletions bench/private-property.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { createBenchmarkSuite } from '../common.mjs'
import PrivateSymbol from 'privsym'

const suite = createBenchmarkSuite('Private Property')

const kWidth = Symbol('width')
const kHeight = Symbol('height')
const pkWidth = PrivateSymbol('width')
const pkHeight = PrivateSymbol('height')

class A {
#foo = 0
Expand Down Expand Up @@ -77,24 +74,6 @@ class SymbolClass {
}
}

class PrivateSymbolClass {
constructor() {
this[pkWidth] = 20
this[pkHeight] = 10
this.publicField = 0
}
get dimension() {
return {
width: this[pkWidth],
height: this[pkHeight],
}
}
increaseSize() {
this[pkWidth]++
this[pkHeight]++
}
}

suite
.add('Raw usage private field', function () {
const a = new A()
Expand Down Expand Up @@ -125,12 +104,5 @@ suite
b.increaseSize()
b.dimension
})
.add('Manipulating private properties using PrivateSymbol', function () {
const b = new PrivateSymbolClass()
b.publicField
b.dimension
b.increaseSize()
b.dimension
})

await suite.runAndPrintResults()

0 comments on commit a1bc662

Please sign in to comment.