Chromium Code Reviews| Index: test/mjsunit/d8-counter.js |
| diff --git a/test/mjsunit/d8-counter.js b/test/mjsunit/d8-counter.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..10113cfc97af3acbd56d6c633700df208a78d2a8 |
| --- /dev/null |
| +++ b/test/mjsunit/d8-counter.js |
| @@ -0,0 +1,66 @@ |
| +// Copyright 2011 the V8 project authors. All rights reserved. |
| +// Redistribution and use in source and binary forms, with or without |
| +// modification, are permitted provided that the following conditions are |
| +// met: |
| +// |
| +// * Redistributions of source code must retain the above copyright |
| +// notice, this list of conditions and the following disclaimer. |
| +// * Redistributions in binary form must reproduce the above |
| +// copyright notice, this list of conditions and the following |
| +// disclaimer in the documentation and/or other materials provided |
| +// with the distribution. |
| +// * Neither the name of Google Inc. nor the names of its |
| +// contributors may be used to endorse or promote products derived |
| +// from this software without specific prior written permission. |
| +// |
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + |
| +// Test the counter module of d8. Work in progress. |
| + |
| +function round(number, digits) { |
| + var multiplier = Math.pow(10, digits); |
| + return Math.round(number*multiplier) / multiplier; |
| +} |
| + |
| +print("compiled code size: " + counter.get("c:V8.TotalCompiledCodeSize")); |
| + |
| +// Test whether all counters have been initialized |
| +assertEquals(173, counter.names().length); |
| + |
| +// Two input files were parsed and compiled |
| +assertEquals(2, counter.get("V8.Parse")); |
| + |
| +// Test math stuff |
| +// Integral of sin^2(x) from 0 to pi is pi/2 |
| +var sum = 0; |
| +var segments = 1000; |
| +var delta = (Math.PI/segments); |
| +for(var i = 0; i < segments; i++) { |
| + var x = i/segments * Math.PI; |
| + sum += Math.sin(x) * delta; |
| + assertEquals(round(Math.tan(x), 7), round(Math.sin(x)/Math.cos(x), 7)); |
| +} |
| + |
| +assertEquals(round(2, 5), round(sum, 5)); |
| + |
| +print("number of transcendental cache misses for Math.sin: " |
| + + counter.get("c:V8.MathSin")); |
| +print("number of transcendental cache misses for Math.cos: " |
| + + counter.get("c:V8.MathCos")); |
| +print("number of transcendental cache misses for Math.tan: " |
| + + counter.get("c:V8.MathTan")); |
| + |
|
Yang
2011/06/29 12:02:20
surprisingly, c:V8.MathSin and c:V8.MathCos both r
|
| +print("total transcendental cache misses: " |
| + + counter.get("c:V8.TranscendentalCacheMiss")); |
| + |
| +print("compiled code size: " + counter.get("c:V8.TotalCompiledCodeSize")); |