Skip to content

Commit

Permalink
add primes benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Oct 30, 2024
1 parent bc700a9 commit 275ed80
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions custom/benchmark/Application.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ component {
, "query-manipulation"
, "request"
, "loops"
, "primes"
];
}

Expand Down
40 changes: 40 additions & 0 deletions custom/benchmark/tests/primes.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

<cfscript>
// see https://luceeserver.atlassian.net/browse/LDEV-1541
function calcPrimes() localmode=true {
ticks = getTickCount();
stopIndex = 250;
primes = [];
divisions = 0;
ArrayAppend(primes, 2);
ArrayAppend(primes, 3);
n = 5;
for (n; n < stopIndex; n += 2) {
isPrime = true;
d = 3;
for (d; d < n; d++) {
divisions++;
if (n % d == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
ArrayAppend(primes, n);
}
}
ticks = (getTickCount() - ticks);
numPrimes = arrayLen(primes);
echo("#numberFormat(divisions)# divisions in #ticks# ms.<br>");
echo("#numberFormat(numPrimes)# prime numbers found below #numberFormat(stopIndex)#");
return numPrimes;
}
numPrimes = calcPrimes();
if ( 53 != numPrimes)
throw "Expected 53 primes, got #numPrimes#";
</cfscript>

0 comments on commit 275ed80

Please sign in to comment.