## JavaScript performance comparison

Revision 2 of this test case created

## Preparation code

</script>
<script>
var tweets;

tweets = data;
});

// https://gist.github.com/1123968
function timetowords(timestamp) {
var words = {
"seconds": "less than a minute",
"minutes": "%d minutes",
"day": "a day",
"days": "%d days",
"months": "%d months",
"years": "%d years"
},
deltaMilliseconds = (new Date().getTime() - timestamp),
seconds = deltaMilliseconds / 1000,
minutes = seconds / 60,
hours = minutes / 60,
days = hours / 24,
years = days / 365;

return seconds < 45 && words.seconds.replace(/%d/i, Math.round(seconds)) || seconds < 90 && words.minute.replace(/%d/i, 1) || minutes < 45 && words.minutes.replace(/%d/i, Math.round(minutes)) || minutes < 90 && words.hour.replace(/%d/i, 1) || hours < 24 && words.hours.replace(/%d/i, Math.round(hours)) || hours < 48 && words.day.replace(/%d/i, 1) || days < 30 && words.days.replace(/%d/i, Math.floor(days)) || days < 60 && words.month.replace(/%d/i, 1) || days < 365 && words.months.replace(/%d/i, Math.floor(days / 30)) || years < 2 && words.year.replace(/%d/i, 1) || words.years.replace(/%d/i, Math.floor(years));
}

// Part of https://github.com/seaofclouds/tweet
function relative_time(a){var b=new Date,c=parseInt((b.getTime()-a)/1e3,10),d="";return c<60?d=c+" s":c<120?d="1m":c<2700?d=parseInt(c/60,10).toString()+"m":c<7200?d="1h":c<86400?d=""+parseInt(c/3600,10).toString()+"h":c<172800?d="1d":d=parseInt(c/86400,10).toString()+"d",d}

</script>

## Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
timetowords
\$.each(tweets, function(i, tweet) {
timetowords(Date.parse(tweet.created_at));
});
pending…
seaofclouds / tweet
\$.each(tweets, function(i, tweet) {
relative_time(Date.parse(tweet.created_at));
});
pending…

## Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page: