blob: 42ee34b61d4974f48058a66dee1bdd6ed1406b18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<!DOCTYPE html>
<html>
<!--
Copyright 2006 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.util.Tracer</title>
<script src="../base.js"></script>
<script>
goog.require('goog.debug.Trace');
goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<script>
function testTracer() {
goog.debug.Trace.initCurrentTrace();
var t = goog.debug.Trace.startTracer('foo');
var sum = 0;
for (var i = 0; i < 100000; i++) {
sum += i;
}
goog.debug.Trace.stopTracer(t);
var trace = goog.debug.Trace.getFormattedTrace();
var lines = trace.split('\n');
assertEquals(8, lines.length);
assertNotNull(lines[0].match(/^\s*\d+\.\d+\s+Start\s+foo$/));
assertNotNull(lines[1].match(/^\s*\d+\s+\d+\.\d+\s+Done\s+\d+ ms\s+foo$/));
}
function testPerf() {
goog.debug.Trace.initCurrentTrace();
var count = 1000;
var start = goog.now();
for (var i = 0; i < count; i++) {
var t = goog.debug.Trace.startTracer('foo');
var t2 = goog.debug.Trace.startTracer('foo.bar');
var t3 = goog.debug.Trace.startTracer('foo.bar.baz');
goog.debug.Trace.stopTracer(t3);
var t4 = goog.debug.Trace.startTracer('foo.bar.bim');
goog.debug.Trace.stopTracer(t4);
goog.debug.Trace.stopTracer(t2);
goog.debug.Trace.stopTracer(t);
}
count *= 4;
var end = goog.now();
}
</script>
</body>
</html>
|