From fab4ada3c849becede839530d812748064654bd6 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 19 Mar 2011 09:57:18 +0530 Subject: Created a performance test harness and reporter --- perf/jsonPerfSpec.js | 34 ++++++++---------------- perf/testUtils.js | 73 ++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 71 insertions(+), 36 deletions(-) (limited to 'perf') diff --git a/perf/jsonPerfSpec.js b/perf/jsonPerfSpec.js index 01a489e2..edc4b6b2 100644 --- a/perf/jsonPerfSpec.js +++ b/perf/jsonPerfSpec.js @@ -1,28 +1,16 @@ describe('json', function() { it('angular parser', function() { - var duration = time(function() { - expect(angular.fromJson(largeJsonString)).toBeTruthy(); - }, 1); - - dump(duration/1 + ' ms per iteration'); - }); - - - it('angular delegating to native parser', function() { - var duration = time(function() { - expect(angular.fromJson(largeJsonString, true)).toBeTruthy(); - }, 100); - - dump(duration/100 + ' ms per iteration'); - }); - - - it('native json', function() { - var duration = time(function() { - expect(JSON.parse(largeJsonString)).toBeTruthy(); - }, 100); - - dump(duration/100 + ' ms per iteration'); + perf( + function angular() { + fromJson(largeJsonString); + }, + function nativeDelegate() { + fromJson(largeJsonString, true); + }, + function nativeJSON() { + JSON.parse(largeJsonString); + } + ); }); }); diff --git a/perf/testUtils.js b/perf/testUtils.js index ca016c31..2fc4f8a2 100644 --- a/perf/testUtils.js +++ b/perf/testUtils.js @@ -1,20 +1,67 @@ if (window.jstestdriver) { jstd = jstestdriver; - dump = angular.bind(jstd.console, jstd.console.log); + dump = bind(jstd.console, jstd.console.log); } -function time(fn, times) { - times = times || 1; +function time(fn) { + var count = 1, + targetTime = 500, + start = new Date().getTime(), + stop = start + targetTime, + elapsed, + end, + iterations, + pad = angularFilter.number; - var i, - start, - duration = 0; - - for (i=0; i