a^n vs n times of a

Benchmark created on


Description

1 + a + a^2 + ... + a^n

Setup

const a = 3
const n = 1000

Test runner

Ready to run.

Testing in
TestOps/sec
O(n)
let result = 1
let power = 1

for (let i = 1; i <= n; i++){
    power *= a 
    result += power
}
ready
O(n^2)
let result = 1

for (let i = 1; i <= n; i++){
    result += a ** i
}
ready

Revisions

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