replacing all isType tests that relied on string comparisons with versions that check for existence of known methods and properties. Less safe, but more than an order of magnitude faster.

This commit is contained in:
Jeremy Ashkenas
2010-01-01 19:05:34 -05:00
parent d49196f2e7
commit 4be6a194cd
3 changed files with 81 additions and 17 deletions

25
test/temp.js Normal file
View File

@@ -0,0 +1,25 @@
(function() {
var func = function(){};
var date = new Date();
var str = "a string";
var numbers = [];
for (var i=0; i<1000; i++) numbers.push(i);
var objects = _.map(numbers, function(n){ return {num : n}; });
var randomized = _.sortBy(numbers, function(){ return Math.random(); });
JSLitmus.test('_.each()', function() {
var timesTwo = [];
_.each(numbers, function(num){ timesTwo.push(num * 2); });
return timesTwo;
});
JSLitmus.test('_.isString', function() {
return _.isString(str);
});
JSLitmus.test('_.isStringNew', function() {
return _.isStringNew(str);
});
})();

19
test/temp_tests.html Normal file
View File

@@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Underscore Temporary Tests</title>
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="vendor/jquery.js"></script>
<script type="text/javascript" src="vendor/jslitmus.js"></script>
<script type="text/javascript" src="../underscore.js"></script>
<script type="text/javascript" src="temp.js"></script>
</head>
<body>
<h1 class="qunit-header">Underscore Temporary Tests</h1>
<h2 class="qunit-userAgent">
A page for temporary speed tests, used for developing faster implementations
of existing Underscore methods.
</h2>
<br />
</body>
</html>