Math or operators

Benchmark created on


Preparation HTML

<script>
let res = isPrime(4)
<script>

Test runner

Ready to run.

Testing in
TestOps/sec
Math
const isPrime = (num: number) => {
  for (
    let index = 2;
	let rootedNum = Math.floor(Math.sqrt(num));
    index <= rootedNum;
    index++
  ) {
    if (num % index === 0) return false;
  }
  return num > 1;
};
ready
Operator
const isPrime = (num: number) => {
  for (
    let index = 2;
    index * index <= number;
    index++
  ) {
    if (num % index === 0) return false;
  }
  return num > 1;
};
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.