|
1 | 1 | describe('json', function() { |
2 | | - xit('should parse json in a reasonable time', function() { |
3 | | - var totalSubstr = 0, |
4 | | - totalGetMatch = 0, |
5 | | - totalConsume = 0, |
6 | | - totalTime = 0, |
7 | | - runTimes = []; |
8 | | - |
9 | | - for (var i=0; i<10; i++) { |
10 | | - window.substrTime = 0; |
11 | | - window.getMatchTime = 0; |
12 | | - window.consumeTime = 0; |
13 | | - var start = Date.now(); |
14 | | - expect(angular.fromJson(largeJsonString)).toBeTruthy(); |
15 | | - var time = Date.now() - start; |
16 | | -// dump('parse time', time, 'consume', window.consumeTime, |
17 | | -// 'substr', window.substrTime, |
18 | | -// 'getMatch', window.getMatchTime); |
19 | | - totalTime += time; |
20 | | - totalSubstr += window.substrTime; |
21 | | - totalGetMatch += window.getMatchTime; |
22 | | - totalConsume += window.consumeTime; |
23 | | - runTimes.push(time); |
24 | | - } |
25 | | - |
26 | | - totalGetMatch = totalGetMatch - totalSubstr; |
27 | | - |
28 | | - dump("totals", totalTime, |
29 | | - "| consume", totalConsume, '' + Math.round(totalConsume/(totalTime/100)) + '%', |
30 | | - "| substr", totalSubstr, '' + Math.round(totalSubstr/(totalTime/100)) + '%', |
31 | | - "| getMatch", totalGetMatch, '' + Math.round(totalGetMatch/(totalTime/100)) + '%'); |
32 | | - dump("run times", runTimes); |
33 | | - delete window.consumeTime; |
34 | | - delete window.substrTime; |
35 | | - delete window.getMatchTime; |
36 | | - }); |
37 | | - |
38 | 2 |
|
39 | 3 | it('angular parser', function() { |
40 | 4 | var duration = time(function() { |
41 | 5 | expect(angular.fromJson(largeJsonString)).toBeTruthy(); |
42 | 6 | }, 1); |
43 | 7 |
|
44 | | - expect(duration).toBeLessThan(4000); |
| 8 | + dump(duration/1 + ' ms per iteration'); |
| 9 | + }); |
| 10 | + |
| 11 | + |
| 12 | + it('angular delegating to native parser', function() { |
| 13 | + var duration = time(function() { |
| 14 | + expect(angular.fromJson(largeJsonString, true)).toBeTruthy(); |
| 15 | + }, 100); |
| 16 | + |
| 17 | + dump(duration/100 + ' ms per iteration'); |
45 | 18 | }); |
46 | 19 |
|
47 | 20 |
|
48 | 21 | it('native json', function() { |
49 | 22 | var duration = time(function() { |
50 | 23 | expect(JSON.parse(largeJsonString)).toBeTruthy(); |
51 | | - }, 1); |
| 24 | + }, 100); |
52 | 25 |
|
53 | | - expect(duration).toBeLessThan(200); |
| 26 | + dump(duration/100 + ' ms per iteration'); |
54 | 27 | }); |
55 | 28 | }); |
0 commit comments