blob: 415acdbc1da64d18cfc20683977062390a17c591 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// |reftest| skip -- bogus perf test (bug 540512)
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 451673;
var summary = 'TM: Tracing prime number generation';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
function doTest(enablejit)
{
if (enablejit)
else
var n = 1000000;
var start = new Date();
var i=0;
var j=0;
var numprimes=0;
var limit=0;
numprimes = 1; // 2 is prime
var mceil = Math.floor;
var msqrt = Math.sqrt;
var isPrime = 1;
for (i = 3; i<= n; i+=2)
{
isPrime=1;
limit = mceil(msqrt(i)+1) + 1;
for (j = 3; j < limit; j+=2)
{
if (i % j == 0)
{
isPrime = 0;
break;
}
}
if (isPrime)
{
numprimes ++;
}
}
var end = new Date();
var timetaken = end - start;
timetaken = timetaken / 1000;
if (enablejit)
print((enablejit ? ' JIT' : 'Non-JIT') + ": Number of primes up to: " + n + " is " + numprimes + ", counted in " + timetaken + " secs.");
return timetaken;
}
var timenonjit = doTest(false);
var timejit = doTest(true);
expect = true;
actual = timejit < timenonjit;
reportCompare(expect, actual, summary);
exitFunc ('test');
}
|