Comparing version 0.1.349 to 0.2.0
@@ -526,3 +526,3 @@ /*! | ||
options = extend(extend({ }, me.constructor.options), options); | ||
me.options = forIn(options, function(value, key) { | ||
me.options = each(options, function(value, key) { | ||
// add event listeners | ||
@@ -542,20 +542,28 @@ if (/^on[A-Z]/.test(key)) { | ||
/** | ||
* A generic bare-bones `Array#forEach` solution. | ||
* A bare-bones `Array#forEach`/`for-in` own property solution. | ||
* Callbacks may terminate the loop by explicitly returning `false`. | ||
* @static | ||
* @member Benchmark | ||
* @param {Array} array The array to iterate over. | ||
* @param {Array|Object} object The object to iterate over. | ||
* @param {Function} callback The function called per iteration. | ||
* @returns {Array} The array iterated over. | ||
* @returns {Array|Object} Returns the object iterated over. | ||
*/ | ||
function each(array, callback) { | ||
function each(object, callback) { | ||
var i = -1, | ||
length = array.length; | ||
length = object.length; | ||
while (++i < length) { | ||
if (i in array && callback(array[i], i, array) === false) { | ||
break; | ||
if (hasKey(object, 'length') && length > -1 && length < 4294967296) { | ||
while (++i < length) { | ||
if (i in object && callback(object[i], i, object) === false) { | ||
break; | ||
} | ||
} | ||
} else { | ||
for (i in object) { | ||
if (hasKey(object, i) && callback(object[i], i, object) === false) { | ||
break; | ||
} | ||
} | ||
} | ||
return array; | ||
return object; | ||
} | ||
@@ -625,19 +633,2 @@ | ||
/** | ||
* A generic bare-bones for-in solution for an object's own properties. | ||
* @static | ||
* @member Benchmark | ||
* @param {Object} object The object to iterate over. | ||
* @param {Function} callback The function called per iteration. | ||
* @returns {Object} The object iterated over. | ||
*/ | ||
function forIn(object, callback) { | ||
for (var key in object) { | ||
if (hasKey(object, key) && callback(object[key], key, object) === false) { | ||
break; | ||
} | ||
} | ||
return object; | ||
} | ||
/** | ||
* Converts a number to a more readable comma-separated string representation. | ||
@@ -677,4 +668,3 @@ * @static | ||
else { | ||
result = key in object && | ||
!(key in parent && object[key] === parent[key]); | ||
result = key in object && !(key in parent && object[key] === parent[key]); | ||
} | ||
@@ -840,3 +830,3 @@ return result; | ||
string = string == null ? '' : string; | ||
forIn(object || { }, function(value, key) { | ||
each(object || { }, function(value, key) { | ||
string = string.replace(RegExp('#\\{' + key + '\\}', 'g'), String(value)); | ||
@@ -852,3 +842,3 @@ }); | ||
* @param {Mixed} value The value to check. | ||
* @returns {Boolean} Returns true if value is an array, else false. | ||
* @returns {Boolean} Returns `true` if value is an array, else `false`. | ||
*/ | ||
@@ -865,3 +855,3 @@ function isArray(value) { | ||
* @param {String} name The name of the class. | ||
* @returns {Boolean} Returns true if of the class, else false. | ||
* @returns {Boolean} Returns `true` if of the class, else `false`. | ||
*/ | ||
@@ -880,3 +870,3 @@ function isClassOf(object, name) { | ||
* @param {String} property The property to check. | ||
* @returns {Boolean} Returns true if the property value is a non-primitive, else false. | ||
* @returns {Boolean} Returns `true` if the property value is a non-primitive, else `false`. | ||
*/ | ||
@@ -904,3 +894,3 @@ function isHostType(object, property) { | ||
separator2 || (separator2 = ': '); | ||
forIn(object, function(value, key) { | ||
each(object, function(value, key) { | ||
pairs.push(key + separator2 + value); | ||
@@ -1036,3 +1026,3 @@ }); | ||
// copy own properties | ||
forIn(me, function(value, key) { | ||
each(me, function(value, key) { | ||
if (!hasKey(result, key)) { | ||
@@ -1244,3 +1234,3 @@ result[key] = /^\d+$/.test(key) ? value.clone() : value; | ||
// copy own properties | ||
forIn(me, function(value, key) { | ||
each(me, function(value, key) { | ||
if (!hasKey(result, key)) { | ||
@@ -1306,4 +1296,3 @@ result[key] = value; | ||
while (pairs.length) { | ||
pair = pairs.pop(); | ||
(isArray(pair[0]) ? each : forIn)(pair[0], check); | ||
each((pair = pairs.pop(), pair[0]), check); | ||
} | ||
@@ -1575,3 +1564,3 @@ if (changed) { | ||
os = 'Android,Cygwin,SymbianOS,webOS[ /]\\d,Linux,Mac OS(?: X)?,Macintosh,Windows 98;,Windows ', | ||
product = 'BlackBerry\\s?\\d+,iP[ao]d,iPhone,Kindle,Nokia,Nook,Samsung,Xoom', | ||
product = 'BlackBerry\\s?\\d+,iP[ao]d,iPhone,Kindle,Nokia,Nook,PlayBook,Samsung,Xoom', | ||
version = isClassOf(window.opera, 'Opera') && opera.version(); | ||
@@ -1751,3 +1740,3 @@ | ||
*/ | ||
'version': '0.1.349', | ||
'version': '0.2.0', | ||
@@ -1762,3 +1751,3 @@ /** | ||
// generic Array#forEach | ||
// generic Array#forEach/for-in | ||
'each': each, | ||
@@ -1772,5 +1761,2 @@ | ||
// iterate over an object's direct properties | ||
'forIn': forIn, | ||
// converts a number to a comma-separated string | ||
@@ -1777,0 +1763,0 @@ 'formatNumber': formatNumber, |
@@ -0,0 +0,0 @@ Copyright Mathias Bynens <http://mathiasbynens.be/> |
{ | ||
"name": "benchmark", | ||
"version": "0.1.349", | ||
"version": "0.2.0", | ||
"description": "A benchmarking library that works on nearly all JavaScript platforms, supports high-resolution timers, and returns statistically significant results.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://benchmarkjs.com/", |
@@ -15,7 +15,11 @@ # Benchmark.js | ||
<script src="benchmark.js"></script> | ||
``` html | ||
<script src="benchmark.js"></script> | ||
``` | ||
Optionally, expose Java’s nanosecond timer by adding the `nano` applet to the `<body>`: | ||
<applet code="nano" archive="nano.jar"></applet> | ||
``` html | ||
<applet code="nano" archive="nano.jar"></applet> | ||
``` | ||
@@ -28,46 +32,58 @@ Or enable Chrome’s microsecond timer by using the [command line switch](http://peter.sh/experiments/chromium-command-line-switches/#enable-benchmarking): | ||
npm install benchmark | ||
``` bash | ||
npm install benchmark | ||
``` | ||
In [Node.js](http://nodejs.org/): | ||
var Benchmark = require('benchmark'); | ||
``` js | ||
var Benchmark = require('benchmark'); | ||
``` | ||
Optionally, use the [microtime module](https://github.com/wadey/node-microtime) by Wade Simmons: | ||
npm install microtime | ||
``` bash | ||
npm install microtime | ||
``` | ||
In [Narwhal](http://narwhaljs.org/) and [RingoJS](http://ringojs.org/): | ||
var Benchmark = require('benchmark').Benchmark; | ||
``` js | ||
var Benchmark = require('benchmark').Benchmark; | ||
``` | ||
In [Rhino](http://www.mozilla.org/rhino/): | ||
load('benchmark.js'); | ||
``` js | ||
load('benchmark.js'); | ||
``` | ||
Usage example: | ||
var suite = new Benchmark.Suite; | ||
// add tests | ||
suite.add('RegExp#test', function() { | ||
/o/.test('Hello World!'); | ||
}) | ||
.add('String#indexOf', function() { | ||
'Hello World!'.indexOf('o') > -1; | ||
}) | ||
// add listeners | ||
.on('cycle', function(bench) { | ||
console.log(String(bench)); | ||
}) | ||
.on('complete', function() { | ||
console.log('Fastest is ' + this.filter('fastest').pluck('name')); | ||
}) | ||
// run async | ||
.run(true); | ||
// logs: | ||
// > RegExp#test × 4,161,532 ±0.99% (59 cycles) | ||
// > String#indexOf × 6,139,623 ±1.00% (131 cycles) | ||
// > Fastest is String#indexOf | ||
``` js | ||
var suite = new Benchmark.Suite; | ||
// add tests | ||
suite.add('RegExp#test', function() { | ||
/o/.test('Hello World!'); | ||
}) | ||
.add('String#indexOf', function() { | ||
'Hello World!'.indexOf('o') > -1; | ||
}) | ||
// add listeners | ||
.on('cycle', function(bench) { | ||
console.log(String(bench)); | ||
}) | ||
.on('complete', function() { | ||
console.log('Fastest is ' + this.filter('fastest').pluck('name')); | ||
}) | ||
// run async | ||
.run(true); | ||
// logs: | ||
// > RegExp#test x 4,161,532 +-0.99% (59 cycles) | ||
// > String#indexOf x 6,139,623 +-1.00% (131 cycles) | ||
// > Fastest is String#indexOf | ||
``` | ||
## Cloning this repo | ||
@@ -77,9 +93,14 @@ | ||
git clone --recursive https://github.com/mathiasbynens/Benchmark.js.git | ||
``` bash | ||
git clone --recursive https://github.com/mathiasbynens/Benchmark.js.git | ||
cd Benchmark.js | ||
``` | ||
For older git versions, just use: | ||
git clone https://github.com/mathiasbynens/Benchmark.js.git | ||
cd Benchmark.js | ||
git submodule update --init | ||
``` bash | ||
git clone https://github.com/mathiasbynens/Benchmark.js.git | ||
cd Benchmark.js | ||
git submodule update --init | ||
``` | ||
@@ -91,6 +112,9 @@ Feel free to fork if you see possible improvements! | ||
* [Mathias Bynens](http://mathiasbynens.be/) | ||
[![twitter/mathias](http://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") | ||
* [John-David Dalton](http://allyoucanleet.com/) | ||
[![twitter/jdalton](http://gravatar.com/avatar/299a3d891ff1920b69c364d061007043?s=70)](https://twitter.com/jdalton "Follow @jdalton on Twitter") | ||
## Contributors | ||
* [Kit Goncharov](http://kitgoncharov.github.com/) | ||
* [Kit Goncharov](http://kitgoncharov.github.com/) | ||
[![twitter/kitgoncharov](http://gravatar.com/avatar/6662a1d02f351b5ef2f8b4d815804661?s=70)](https://twitter.com/kitgoncharov "Follow @kitgoncharov on Twitter") |
@@ -378,2 +378,12 @@ module("Benchmark.platform"); | ||
'IE 10.0 on Windows Server 2008 / Vista': { | ||
'ua': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.0; Trident/6.0)', | ||
'mode': 10 | ||
}, | ||
'IE 10.0 (running in IE 9 mode) on Windows Server 2008 R2 / 7': { | ||
'ua': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)', | ||
'mode': 9 | ||
}, | ||
'IE Mobile 7.0 on Samsung (Windows Phone OS 7.0)': { | ||
@@ -513,2 +523,6 @@ 'ua': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; SAMSUNG; OMNIA7)' | ||
'PlayBook Browser 0.0.1 (like Safari 4+)': { | ||
'ua': 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.8+ (KHTML, like Gecko) Version/0.0.1 Safari/534.8+' | ||
}, | ||
'Rhino': { | ||
@@ -940,3 +954,3 @@ 'global': { }, | ||
Benchmark.forIn(Tests, function(value, key) { | ||
Benchmark.each(Tests, function(value, key) { | ||
var platform = getPlatform(value); | ||
@@ -949,3 +963,3 @@ key = Benchmark.interpolate(key, { 'alpha': '\u03b1', 'beta': '\u03b2' }); | ||
// test null values | ||
Benchmark.forIn(platform, function(value, key) { | ||
Benchmark.each(platform, function(value, key) { | ||
if (!value) { | ||
@@ -952,0 +966,0 @@ strictEqual(value, null, 'Benchmark.platform.' + key); |
151627
116
11
2874