|
| 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 | + |
| 39 | + it('angular parser', function() { |
| 40 | + var duration = time(function() { |
| 41 | + expect(angular.fromJson(largeJsonString)).toBeTruthy(); |
| 42 | + }, 1); |
| 43 | + |
| 44 | + expect(duration).toBeLessThan(4000); |
| 45 | + }); |
| 46 | + |
| 47 | + |
| 48 | + it('native json', function() { |
| 49 | + var duration = time(function() { |
| 50 | + expect(JSON.parse(largeJsonString)).toBeTruthy(); |
| 51 | + }, 1); |
| 52 | + |
| 53 | + expect(duration).toBeLessThan(200); |
| 54 | + }); |
| 55 | +}); |
0 commit comments