I’m trying to figure out what version of project euler’s sum primes is better, I’m using sieve of eranthoses a bit improved and I’ve created a first for loop which will change all even values to false and then allowing the next loop to increment by 2, reducing the isPrime calls (look at the code and comments), I’m really no expert by calculating time complexities but it should be around the same time complexity between this code and this code without the first loop but second loop increments by 1 instead of 2, you also have this runtime function to test but my shitty computer isn’t consistent at all, especially with tests running, so which one is more efficient? with or without the loop?

thanks in advance

also any tips for managing memory better without diving too deep?

**Your code so far**

```
function primeSummation(n) {
var arr = Array(n).fill(true);
arr[0] = false;
arr[1] = false;
for (let i = 2; i < arr.length; i+=2) {
arr[i] = false;
}
/*im doing this for loop so that we could add +=2 to the
next loop, which will reduce calls to isPrime, but is it
worth it? because isPrime will yield falso immediately*/
arr[2] = true; //we changed it in the loop but 2 is prime
for (let i = 3; i <= Math.sqrt(n); i+=2) {
if (isPrime(i)) { /*I think it will signifcantly reduce
the time complexity since that if we iterated through
3 iterating through 9 or 6 or 18 will be a waste of time*/
for (let j = i*i; j < arr.length; j+=i) {
arr[j] = false;
}
}
}
return arr.reduce((sum, k, i) => k ? sum+i : sum+0, 0);
}
function isPrime(n) {
for (let i = 2; i <= Math.sqrt(n); i++) {
if (n % i === 0) return false;
}
return true;
}
function run_function(func, test_values) {
for(let i in test_values){
console.log('Test value:', test_values[i]);
var t0 = performance.now();
console.log('Output:', func(test_values[i]));
var t1 = performance.now();
console.log("Took " + (t1 - t0) + " ms");
}
}
var a = [17, 2001, 140759, 2000000]
run_function(primeSummation, a)
```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36`

.

**Challenge:** Problem 10: Summation of primes

**Link to the challenge:**