Benchmark method takes an optional repeat count after the description. Refactor benchmark helper.

This commit is contained in:
Nathan Sobo
2012-05-09 18:11:31 -06:00
parent 13f89f5d96
commit b369c09fa0
2 changed files with 13 additions and 14 deletions

View File

@@ -15,23 +15,22 @@ keymap.bindKeys '*',
$(document).on 'close', -> window.close()
$(document).on 'show-console', -> window.showConsole()
window.fpbenchmarkOnce = (description, fn) -> window.profile(1, description, fn, true)
window.pfbenchmark = window.fpbenchmarkOnce
defaultCount = 100
window.fpbenchmark = (description, fn) -> window.profile(defaultCount, description, fn, true)
window.pbenchmark = (args...) -> window.benchmark(args..., profile: true)
window.fbenchmark = (args...) -> window.benchmark(args..., focused: true)
window.fpbenchmark = (args...) -> window.benchmark(args..., profile: true, focused: true)
window.pfbenchmark = window.fpbenchmark
window.pbenchmark = (description, fn) -> window.profile(defaultCount, description, fn, false)
window.fbenchmark = (description, fn) -> window.benchmark(description, fn, false, true)
window.profile = (count, description, fn, focused) ->
window.showConsole()
window.rawBenchmark(count, description, fn, true, focused)
window.benchmark = (args...) ->
description = args.shift()
if typeof args[0] is 'number'
count = args.shift()
else
count = defaultCount
[fn, options] = args
{ profile, focused } = (options ? {})
window.benchmarkOnce = (args...) -> window.rawBenchmark(1, args...)
window.benchmark = (args...) -> window.rawBenchmark(defaultCount, args...)
window.rawBenchmark = (count, description, fn, profile=false, focused=false) ->
window.showConsole() if profile
method = if focused then fit else it
method description, ->
total = measure ->

View File

@@ -42,7 +42,7 @@ describe "editor.", ->
editor.backspace()
describe "9000-line-file.", ->
benchmarkOnce "opening", ->
benchmark "opening", 1, ->
editor.setBuffer new Buffer(require.resolve('fixtures/huge.js'))
describe "at-end.", ->