Integer vs Boolean array Swift Performance
<p>I tried executing Sieve Of Eratosthenes algorithm using a large Integer array and a large Bool array. </p>

<p>The integer version seems to execute MUCH faster than the boolean one. What is the possible reason for this?</p>

<pre><code>import Foundation

var n : Int = 100000000;

var prime = [Bool](repeating: true, count: n+1)
var p = 2
let start = DispatchTime.now()
while((p*p)&lt;=n)
{
    if(prime[p] == true)
    {
        var i = p*2
        while (i&lt;=n)
        {
            prime[i] = false
            i = i + p
        }
    }
    p = p+1
}
let stop = DispatchTime.now()    
let time = (Double)(stop.uptimeNanoseconds - start.uptimeNanoseconds) / 1000000.0

print("Time = \(time) ms")
</code></pre>

<p>Boolean array execution time : 78223.342295 ms</p>

<pre><code>import Foundation

var n : Int = 100000000;

var prime = [Int](repeating: 1, count: n+1)
var p = 2
let start = DispatchTime.now()
while((p*p)&lt;=n)
{
    if(prime[p] == 1)
    {
        var i = p*2
        while (i&lt;=n)
        {
            prime[i] = 0
            i = i + p
        }
    }
    p = p+1
}
let stop = DispatchTime.now()

let time = (Double)(stop.uptimeNanoseconds - start.uptimeNanoseconds) / 1000000.0

print("Time = \(time) ms")
</code></pre>

<p>Integer array execution time : 8535.54546 ms</p>