js/src/tests/js1_8_1/jit/regress-451673.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_8_1/jit/regress-451673.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +// |reftest| skip -- bogus perf test (bug 540512)
     1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +//-----------------------------------------------------------------------------
    1.11 +var BUGNUMBER = 451673;
    1.12 +var summary = 'TM: Tracing prime number generation';
    1.13 +var actual = '';
    1.14 +var expect = '';
    1.15 +
    1.16 +
    1.17 +//-----------------------------------------------------------------------------
    1.18 +test();
    1.19 +//-----------------------------------------------------------------------------
    1.20 +
    1.21 +function test()
    1.22 +{
    1.23 +  enterFunc ('test');
    1.24 +  printBugNumber(BUGNUMBER);
    1.25 +  printStatus (summary);
    1.26 +
    1.27 +  function doTest(enablejit)
    1.28 +  {
    1.29 +    if (enablejit)
    1.30 +      jit(true);
    1.31 +    else
    1.32 +      jit(false);
    1.33 +
    1.34 +    var n = 1000000;
    1.35 +    var start = new Date();
    1.36 +    var i=0;
    1.37 +    var j=0;
    1.38 +    var numprimes=0;
    1.39 +    var limit=0;
    1.40 +    numprimes = 1; // 2 is prime
    1.41 +    var mceil = Math.floor;
    1.42 +    var msqrt = Math.sqrt;
    1.43 +    var isPrime = 1;
    1.44 +
    1.45 +    for (i = 3; i<= n; i+=2)
    1.46 +    {
    1.47 +	    isPrime=1;
    1.48 +	    limit = mceil(msqrt(i)+1) + 1;
    1.49 +
    1.50 +	    for (j = 3; j < limit; j+=2)
    1.51 +      {
    1.52 +		    if (i % j == 0)
    1.53 +        {
    1.54 +			    isPrime = 0;
    1.55 +			    break;
    1.56 +        }
    1.57 +      }
    1.58 +
    1.59 +	    if (isPrime)
    1.60 +      {
    1.61 +		    numprimes ++;
    1.62 +      }
    1.63 +    }
    1.64 +
    1.65 +    var end = new Date();
    1.66 +
    1.67 +    var timetaken = end - start;
    1.68 +    timetaken = timetaken / 1000;
    1.69 +
    1.70 +    if (enablejit)
    1.71 +      jit(false);
    1.72 +
    1.73 +    print((enablejit ? '    JIT' : 'Non-JIT') + ": Number of primes up to: " + n + " is " + numprimes + ", counted in " + timetaken + " secs.");
    1.74 +
    1.75 +    return timetaken;
    1.76 +  }
    1.77 +
    1.78 +  var timenonjit = doTest(false);
    1.79 +  var timejit    = doTest(true);
    1.80 +
    1.81 +  expect = true;
    1.82 +  actual = timejit < timenonjit;
    1.83 +
    1.84 +  reportCompare(expect, actual, summary);
    1.85 +
    1.86 +  exitFunc ('test');
    1.87 +}

mercurial