Add benchmark for inserting and deleting a character

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-03-07 19:07:56 -07:00
parent 18c8c7e14f
commit f44a9df701
3 changed files with 34 additions and 10 deletions

View File

@@ -7,20 +7,32 @@ Point = require 'point'
require 'window'
window.showConsole()
beforeEach ->
window.keymap = new Keymap
afterEach ->
$('#jasmine-content').empty()
keymap = new Keymap
keymap.bindDefaultKeys()
$(window).on 'keydown', (e) -> keymap.handleKeyEvent(e)
keymap.bindKeys '*', 'meta-w': 'close'
$(document).on 'close', -> window.close()
window.benchmark = (description, fn) ->
it description, fn
window.profile = (description, fn) ->
window.benchmark(description, fn, true)
window.benchmark = (description, fn, profile=false) ->
it description, ->
count = 50
total = measure ->
console.profile(description) if profile
_.times count, fn
console.profileEnd(description) if profile
avg = total / count
report = "#{description}: #{total} / #{count} = #{avg}ms"
console.log report
throw new Error(report)
window.measure = (fn) ->
start = new Date().getTime()
fn()
new Date().getTime() - start
window.waitsForPromise = (fn) ->
window.waitsFor (moveOn) ->

View File

@@ -2,6 +2,17 @@ fs = require 'fs'
require 'benchmark-helper'
describe "Editor", ->
benchmark "inserting and deleting a character", ->
editor = null
beforeEach ->
window.rootViewParentSelector = '#jasmine-content'
window.startup()
editor = rootView.editor
afterEach ->
window.shutdown()
profile "inserting and deleting a character", ->
editor.hiddenInput.textInput('x')
editor.backspace()

View File

@@ -11,6 +11,7 @@ require 'jquery-extensions'
# the DOM window.
windowAdditions =
rootViewParentSelector: 'body'
rootView: null
keymap: null
@@ -45,7 +46,7 @@ windowAdditions =
attachRootView: (url) ->
@rootView = new RootView {url}
$('body').append @rootView
$(@rootViewParentSelector).append @rootView
requireStylesheet: (path) ->
fullPath = require.resolve(path)