From 31e4e631f96d3d13c32823577552a24c846e46bb Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 9 Mar 2013 18:15:32 -0800 Subject: [PATCH] Cleanup test.js and perf.js and add `_(array)` benchmark. Former-commit-id: bcd120c9ee332db39c7b637894751f2861bac069 --- perf/index.html | 1 + perf/perf.js | 57 +++++++++++++++++++++++------------------------- perf/run-perf.sh | 2 +- test/test.js | 16 ++++++-------- 4 files changed, 36 insertions(+), 40 deletions(-) diff --git a/perf/index.html b/perf/index.html index 5fe5abbc2..47443078c 100644 --- a/perf/index.html +++ b/perf/index.html @@ -29,6 +29,7 @@
+ diff --git a/perf/perf.js b/perf/perf.js index 0734cf0c8..5a0e0de80 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -25,27 +25,25 @@ return result; }()); - /** Load Benchmark.js */ - var Benchmark = - window.Benchmark || ( - Benchmark = load('../vendor/benchmark.js/benchmark.js') || window.Benchmark, - Benchmark.Benchmark || Benchmark - ); - /** Load Lo-Dash */ - var lodash = - window.lodash || ( - lodash = load(filePath) || window._, - lodash = lodash._ || lodash, - lodash.noConflict() - ); + var lodash = window.lodash || (window.lodash = ( + lodash = load(filePath) || window._, + lodash = lodash._ || lodash, + lodash.noConflict() + )); + + /** Load Benchmark.js */ + var Benchmark = window.Benchmark || (window.Benchmark = ( + Benchmark = load('../vendor/benchmark.js/benchmark.js') || window.Benchmark, + Benchmark = Benchmark.Benchmark || Benchmark, + Benchmark.runInContext(lodash.extend({}, window, { '_': lodash })) + )); /** Load Underscore */ - var _ = - window._ || ( - _ = load('../vendor/underscore/underscore.js') || window._, - _._ || _ - ); + var _ = window._ || (window._ = ( + _ = load('../vendor/underscore/underscore.js') || window._, + _._ || _ + )); /** Used to access the Firebug Lite panel (set by `run`) */ var fbPanel; @@ -68,16 +66,6 @@ /** The other library basename */ var otherName = basename(ui.otherPath, '.js'); - /** Expose functions to the global object */ - window._ = _; - window.Benchmark = Benchmark; - window.lodash = lodash; - - /** Add `console.log()` support for Narwhal and RingoJS */ - if (!window.console && window.print) { - window.console = { 'log': window.print }; - } - /*--------------------------------------------------------------------------*/ /** @@ -201,8 +189,7 @@ lodash.extend(Benchmark.options, { 'async': true, 'setup': '\ - var window = Function("return this || global")(),\ - _ = window._,\ + var _ = window._,\ lodash = window.lodash,\ belt = this.name == "Lo-Dash" ? lodash : _;\ \ @@ -471,6 +458,16 @@ ) ); + suites.push( + Benchmark.Suite('`_(...)` with an array') + .add(buildName, '\ + lodash(numbers)' + ) + .add(otherName, '\ + _(numbers)' + ) + ); + suites.push( Benchmark.Suite('`_(...)` with an object') .add(buildName, '\ diff --git a/perf/run-perf.sh b/perf/run-perf.sh index 8593cd6bd..b1406315b 100755 --- a/perf/run-perf.sh +++ b/perf/run-perf.sh @@ -3,7 +3,7 @@ cd "$(dirname "$0")" echo "Running performance suite in node..." node perf.js ../dist/lodash.js && node perf.js ../dist/lodash.min.js -for cmd in rhino narwhal ringo phantomjs; do +for cmd in rhino "rhino -require" narwhal ringo phantomjs; do echo "" echo "Running performance suite in $cmd..." $cmd perf.js ../dist/lodash.compat.js && $cmd perf.js ../dist/lodash.compat.min.js diff --git a/test/test.js b/test/test.js index b2fbace05..aea6b6ca9 100644 --- a/test/test.js +++ b/test/test.js @@ -43,19 +43,17 @@ }()); /** The `lodash` function to test */ - var _ = - window._ || ( - _ = load(filePath) || window._, - _ = _._ || _, - _.runInContext(window) - ); + var _ = window._ || (window._ = ( + _ = load(filePath) || window._, + _ = _._ || _, + _.runInContext(window) + )); /** The `platform` object to check */ - var platform = ( - window.platform || + var platform = window.platform || (window.platform = ( load('../vendor/platform.js/platform.js') || window.platform - ); + )); /** Used to pass falsey values to methods */ var falsey = [