From 18c8c7e14f79db3d3bce2a7f6c686ccb1848a27b Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Wed, 7 Mar 2012 18:21:07 -0700 Subject: [PATCH] Add benchmark suite, which runs with ctrl-alt-meta-b --- Atom/MainMenu.xib | 74 ++++++++++++++++----- Atom/src/Atom.h | 1 + Atom/src/Atom.mm | 18 ++++-- Atom/src/AtomController.h | 1 + Atom/src/AtomController.mm | 4 ++ benchmark/benchmark-bootstrap.coffee | 24 +++++++ benchmark/benchmark-helper.coffee | 96 ++++++++++++++++++++++++++++ benchmark/benchmark-suite.coffee | 7 ++ src/stdlib/require.coffee | 1 + 9 files changed, 206 insertions(+), 20 deletions(-) create mode 100644 benchmark/benchmark-bootstrap.coffee create mode 100644 benchmark/benchmark-helper.coffee create mode 100644 benchmark/benchmark-suite.coffee diff --git a/Atom/MainMenu.xib b/Atom/MainMenu.xib index 56eb0e2d2..090bbbbc6 100755 --- a/Atom/MainMenu.xib +++ b/Atom/MainMenu.xib @@ -2,10 +2,10 @@ 1050 - 11C74 + 11D50b 1938 - 1138.23 - 567.00 + 1138.32 + 568.00 com.apple.InterfaceBuilder.CocoaPlugin 1938 @@ -68,6 +68,15 @@ + + + Run Benchmarks + b + 1835008 + 2147483647 + + + Quit @@ -115,6 +124,14 @@ 449 + + + runBenchmarks: + + + + 452 + @@ -171,6 +188,7 @@ YES + @@ -189,6 +207,11 @@ + + 450 + + + @@ -201,6 +224,7 @@ 29.IBPluginDependency 389.IBPluginDependency 441.IBPluginDependency + 450.IBPluginDependency 56.IBPluginDependency 57.IBPluginDependency 58.IBPluginDependency @@ -216,6 +240,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -230,7 +255,7 @@ - 449 + 452 @@ -239,14 +264,35 @@ Atom NSApplication - runSpecs: - id + YES + + YES + runBenchmarks: + runSpecs: + + + YES + id + id + - runSpecs: - - runSpecs: - id + YES + + YES + runBenchmarks: + runSpecs: + + + YES + + runBenchmarks: + id + + + runSpecs: + id + @@ -262,10 +308,6 @@ com.apple.InterfaceBuilder.CocoaPlugin.macosx - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 @@ -281,8 +323,8 @@ YES - {9, 8} - {7, 2} + {11, 11} + {10, 3} diff --git a/Atom/src/Atom.h b/Atom/src/Atom.h index b71f03a28..1f4f314c1 100755 --- a/Atom/src/Atom.h +++ b/Atom/src/Atom.h @@ -14,6 +14,7 @@ class ClientHandler; - (void)open:(NSString *)path; - (IBAction)runSpecs:(id)sender; +- (IBAction)runBenchmarks:(id)sender; @end diff --git a/Atom/src/Atom.mm b/Atom/src/Atom.mm index d8ebe4d73..8d95a62c2 100755 --- a/Atom/src/Atom.mm +++ b/Atom/src/Atom.mm @@ -5,6 +5,10 @@ #import "native_handler.h" #import "client_handler.h" +@interface Atom () +- (CefRefPtr)atomContext; +@end + // Provide the CefAppProtocol implementation required by CEF. @implementation Atom @@ -63,13 +67,19 @@ } - (void)open:(NSString *)path { - CefRefPtr atomContext = _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context(); - [[AtomController alloc] initWithPath:path atomContext:atomContext]; + [[AtomController alloc] initWithPath:path atomContext:[self atomContext]]; } - (IBAction)runSpecs:(id)sender { - CefRefPtr atomContext = _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context(); - [[AtomController alloc] initSpecsWithAtomContext:atomContext]; + [[AtomController alloc] initSpecsWithAtomContext:[self atomContext]]; +} + +- (IBAction)runBenchmarks:(id)sender { + [[AtomController alloc] initBenchmarksWithAtomContext:[self atomContext]]; +} + +- (CefRefPtr)atomContext { + return _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context(); } - (void)applicationWillFinishLaunching:(NSNotification *)notification { diff --git a/Atom/src/AtomController.h b/Atom/src/AtomController.h index fd630dc11..c5b7ff43d 100644 --- a/Atom/src/AtomController.h +++ b/Atom/src/AtomController.h @@ -17,6 +17,7 @@ class ClientHandler; - (id)initWithBootstrapScript:(NSString *)bootstrapScript atomContext:(CefRefPtr) context; - (id)initWithPath:(NSString *)path atomContext:(CefRefPtr)atomContext; - (id)initSpecsWithAtomContext:(CefRefPtr)atomContext; +- (id)initBenchmarksWithAtomContext:(CefRefPtr)atomContext; - (void)createBrowser; diff --git a/Atom/src/AtomController.mm b/Atom/src/AtomController.mm index f07edbd2a..62477510b 100644 --- a/Atom/src/AtomController.mm +++ b/Atom/src/AtomController.mm @@ -36,6 +36,10 @@ return [self initWithBootstrapScript:@"spec-bootstrap" atomContext:atomContext]; } +- (id)initBenchmarksWithAtomContext:(CefRefPtr)atomContext { + return [self initWithBootstrapScript:@"benchmark-bootstrap" atomContext:atomContext]; +} + - (void)windowDidLoad { [self.window setDelegate:self]; [self.window setReleasedWhenClosed:NO]; diff --git a/benchmark/benchmark-bootstrap.coffee b/benchmark/benchmark-bootstrap.coffee new file mode 100644 index 000000000..af5916cde --- /dev/null +++ b/benchmark/benchmark-bootstrap.coffee @@ -0,0 +1,24 @@ +{$$} = require 'space-pen' +nakedLoad 'jasmine' +nakedLoad 'jasmine-html' +nakedLoad 'jasmine-focused' + +$ = require 'jquery' + +$('head').append $$ -> + @link rel: "stylesheet", type: "text/css", href: "static/jasmine.css" + +$('body').append $$ -> + @div id: 'jasmine_runner' + @div id: 'jasmine-content' + +jasmineEnv = jasmine.getEnv() +trivialReporter = new jasmine.TrivialReporter(document, 'jasmine_runner') + +jasmineEnv.addReporter(trivialReporter) + +jasmineEnv.specFilter = (spec) -> trivialReporter.specFilter(spec) + +require 'benchmark-suite' +jasmineEnv.execute() + diff --git a/benchmark/benchmark-helper.coffee b/benchmark/benchmark-helper.coffee new file mode 100644 index 000000000..34a071e82 --- /dev/null +++ b/benchmark/benchmark-helper.coffee @@ -0,0 +1,96 @@ +nakedLoad 'jasmine-jquery' +$ = require 'jquery' +_ = require 'underscore' +Keymap = require 'keymap' +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.waitsForPromise = (fn) -> + window.waitsFor (moveOn) -> + fn().done(moveOn) + +window.eventPropertiesForPattern = (pattern) -> + [modifiers..., key] = pattern.split '-' + + modifiers.push 'shift' if key == key.toUpperCase() and key.toUpperCase() != key.toLowerCase() + charCode = key.toUpperCase().charCodeAt 0 + + isNamedKey = key.length > 1 + if isNamedKey + keyIdentifier = key + else + keyIdentifier = "U+00" + charCode.toString(16) + + ctrlKey: 'ctrl' in modifiers + altKey: 'alt' in modifiers + shiftKey: 'shift' in modifiers + metaKey: 'meta' in modifiers + which: charCode + originalEvent: + keyIdentifier: keyIdentifier + +window.keydownEvent = (pattern, properties={}) -> + event = $.Event "keydown", _.extend(eventPropertiesForPattern(pattern), properties) + event.keystroke = (new Keymap).keystrokeStringForEvent(event) + event + +window.clickEvent = (properties={}) -> + $.Event "click", properties + +window.mouseEvent = (type, properties) -> + if properties.point + {point, editor} = properties + {top, left} = @pagePixelPositionForPoint(editor, point) + properties.pageX = left + 1 + properties.pageY = top + 1 + properties.originalEvent ?= {detail: 1} + $.Event type, properties + +window.mousedownEvent = (properties={}) -> + window.mouseEvent('mousedown', properties) + +window.mousemoveEvent = (properties={}) -> + window.mouseEvent('mousemove', properties) + +window.pagePixelPositionForPoint = (editor, point) -> + point = Point.fromObject point + top = editor.lines.offset().top + point.row * editor.lineHeight + left = editor.lines.offset().left + point.column * editor.charWidth - editor.lines.scrollLeft() + { top, left } + +window.setEditorWidthInChars = (editor, widthInChars, charWidth=editor.charWidth) -> + editor.width(charWidth * widthInChars + editor.lines.position().left) + +$.fn.resultOfTrigger = (type) -> + event = $.Event(type) + this.trigger(event) + event.result + +$.fn.enableKeymap = -> + @on 'keydown', (e) => window.keymap.handleKeyEvent(e) + +$.fn.attachToDom = -> + $('#jasmine-content').append(this) + +$.fn.textInput = (data) -> + event = document.createEvent 'TextEvent' + event.initTextEvent('textInput', true, true, window, data) + this.each -> this.dispatchEvent(event) + diff --git a/benchmark/benchmark-suite.coffee b/benchmark/benchmark-suite.coffee new file mode 100644 index 000000000..f240d0dd9 --- /dev/null +++ b/benchmark/benchmark-suite.coffee @@ -0,0 +1,7 @@ +fs = require 'fs' +require 'benchmark-helper' + +describe "Editor", -> + benchmark "inserting and deleting a character", -> + + diff --git a/src/stdlib/require.coffee b/src/stdlib/require.coffee index 887f5327c..6c6eb4b60 100644 --- a/src/stdlib/require.coffee +++ b/src/stdlib/require.coffee @@ -1,5 +1,6 @@ paths = [ "#{atom.loadPath}/spec" + "#{atom.loadPath}/benchmark" "#{atom.loadPath}/src/stdlib" "#{atom.loadPath}/src/atom" "#{atom.loadPath}/src"