Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
This test data is taken from atom/atom#979 (comment),
Browse files Browse the repository at this point in the history
thanks for the @hokein's effort.

The test has an excessive long line. Making this benchmark fast
will result faster parsing for some real-world peculiar files.
  • Loading branch information
omo committed Mar 19, 2015
1 parent b89c0d8 commit 04eb161
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
59 changes: 33 additions & 26 deletions benchmark/benchmark.coffee
Expand Up @@ -4,29 +4,36 @@ fs = require 'fs'
path = require 'path'
{OnigScanner} = require '../src/oniguruma'

scanner = new OnigScanner(['this', 'var', 'selector', 'window'])

lines = fs.readFileSync(path.join(__dirname, 'large.js'), 'utf8').split('\n')

startTime = Date.now()
matches = 0

for line in lines
for position in [0..line.length]
matches++ if scanner.findNextMatchSync(line, position)

console.log "sync: #{matches} matches in #{Date.now() - startTime}ms"

matches = 0
callsInProgress = 0

callback = (error, match) ->
matches++ if match?
if --callsInProgress is 0
console.log "async: #{matches} matches in #{Date.now() - startTime}ms"

startTime = Date.now()
for line in lines
for position in [0..line.length]
callsInProgress++
scanner.findNextMatch(line, position, callback)
runBenchmarkSync = (lines, scanner) ->
startTime = Date.now()
matches = 0

for line in lines
for position in [0..line.length]
matches++ if scanner.findNextMatchSync(line, position)

console.log "sync: #{matches} matches in #{Date.now() - startTime}ms"

runBenchmarkAsync = (lines, scanner) ->
matches = 0
callsInProgress = 0

callback = (error, match) ->
matches++ if match?
if --callsInProgress is 0
console.log "async: #{matches} matches in #{Date.now() - startTime}ms"

startTime = Date.now()
for line in lines
for position in [0..line.length]
callsInProgress++
scanner.findNextMatch(line, position, callback)

console.log 'oneline.js'
runBenchmarkSync(fs.readFileSync(path.join(__dirname, 'oneline.js'), 'utf8').split('\n'),
new OnigScanner(['\\[', '\\]', '\\{', '\\}']))
console.log 'large.js'
runBenchmarkSync(fs.readFileSync(path.join(__dirname, 'large.js'), 'utf8').split('\n'),
new OnigScanner(['this', 'var', 'selector', 'window']))
runBenchmarkAsync(fs.readFileSync(path.join(__dirname, 'large.js'), 'utf8').split('\n'),
new OnigScanner(['this', 'var', 'selector', 'window']))
1 change: 1 addition & 0 deletions benchmark/oneline.js

Large diffs are not rendered by default.

0 comments on commit 04eb161

Please sign in to comment.