Skip to content

Commit

Permalink
Refactor string benchmark suites and update benchmark results
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday authored and RafaelGSS committed Apr 23, 2024
1 parent 45e6e67 commit 12179fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bench/string-endsWith.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { createBenchmarkSuite } = require('../common')

const suite = createBenchmarkSuite('Check if string ends with a substring')
const suite = createBenchmarkSuite('endsWith comparison')
const shortString = 'foobar'
const longString = 'foobar'.repeat(100)

Expand Down
27 changes: 19 additions & 8 deletions bench/string-startsWith.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
const { createBenchmarkSuite } = require('../common')

const suite = createBenchmarkSuite('Check if string starts with a substring')
const suite = createBenchmarkSuite('startsWith comparison')
const shortString = 'foobar'
const longString = 'foobar'.repeat(100)

const comparison = 'foo'
const comparison2 = 'bar'

suite.add('(short string) (true) String#startsWith', function () {
suite
.add('(short string) (true) String#startsWith', function () {
shortString.startsWith(comparison)
}
).add('(short string) (true) String#slice and strict comparison', function () {
)
.add('(short string) (true) String#slice and String#indexOf', function () {
shortString.slice(0, comparison.length).indexOf(comparison) === 0
}
)
.add('(short string) (true) String#slice and strict comparison', function () {
shortString.slice(0, comparison.length) === comparison
}
)
.add('(long string) (true) String#startsWith', function () {
longString.startsWith(comparison)
}
).add('(long string) (true) String#slice and strict comparison', function () {
)
.add('(long string) (true) String#slice and strict comparison', function () {
longString.slice(0, comparison.length) === comparison
}
)
.add('(short string) (false) String#startsWith', function () {
shortString.startsWith(comparison2)
}
).add('(short string) (false) String#slice and strict comparison', function () {
)
.add('(short string) (false) String#slice and strict comparison', function () {
shortString.slice(0, comparison2.length) === comparison2
}
).add('(long string) (false) String#startsWith', function () {
)
.add('(long string) (false) String#startsWith', function () {
longString.startsWith(comparison2)
}
).add('(long string) (false) String#slice and strict comparison', function () {
)
.add('(long string) (false) String#slice and strict comparison', function () {
longString.slice(0, comparison2.length) === comparison2
}
).run({ async: false })
)
.run({ async: false })

0 comments on commit 12179fe

Please sign in to comment.