michael@0: // |reftest| skip -- bogus perf test (bug 540512) michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 451673; michael@0: var summary = 'TM: Tracing prime number generation'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: function doTest(enablejit) michael@0: { michael@0: if (enablejit) michael@0: jit(true); michael@0: else michael@0: jit(false); michael@0: michael@0: var n = 1000000; michael@0: var start = new Date(); michael@0: var i=0; michael@0: var j=0; michael@0: var numprimes=0; michael@0: var limit=0; michael@0: numprimes = 1; // 2 is prime michael@0: var mceil = Math.floor; michael@0: var msqrt = Math.sqrt; michael@0: var isPrime = 1; michael@0: michael@0: for (i = 3; i<= n; i+=2) michael@0: { michael@0: isPrime=1; michael@0: limit = mceil(msqrt(i)+1) + 1; michael@0: michael@0: for (j = 3; j < limit; j+=2) michael@0: { michael@0: if (i % j == 0) michael@0: { michael@0: isPrime = 0; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: if (isPrime) michael@0: { michael@0: numprimes ++; michael@0: } michael@0: } michael@0: michael@0: var end = new Date(); michael@0: michael@0: var timetaken = end - start; michael@0: timetaken = timetaken / 1000; michael@0: michael@0: if (enablejit) michael@0: jit(false); michael@0: michael@0: print((enablejit ? ' JIT' : 'Non-JIT') + ": Number of primes up to: " + n + " is " + numprimes + ", counted in " + timetaken + " secs."); michael@0: michael@0: return timetaken; michael@0: } michael@0: michael@0: var timenonjit = doTest(false); michael@0: var timejit = doTest(true); michael@0: michael@0: expect = true; michael@0: actual = timejit < timenonjit; michael@0: michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: exitFunc ('test'); michael@0: }