Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

This algorithm is a slightly optimized version of Martin R's answerMartin R's answer.

OP's algorithmOP's algorithm:

h.j.k.'s algorithmh.j.k.'s algorithm:

JS1's algorithmJS1's algorithm:

thepace's algorithmthepace's algorithm is currently a WIP.

Credit must go to Martin RMartin R for the original solution.

This algorithm is a slightly optimized version of Martin R's answer.

OP's algorithm:

h.j.k.'s algorithm:

JS1's algorithm:

thepace's algorithm is currently a WIP.

Credit must go to Martin R for the original solution.

This algorithm is a slightly optimized version of Martin R's answer.

OP's algorithm:

h.j.k.'s algorithm:

JS1's algorithm:

thepace's algorithm is currently a WIP.

Credit must go to Martin R for the original solution.

deleted 289 characters in body
Source Link
wei2912
  • 1.3k
  • 8
  • 26

Alnitak's algorithm:

Algorithm: Alnitak's algorithm
Time required to calculate in nanoseconds: 47100

My algorithm:

Algorithm: wei2912's algorithm
Time required to calculate in nanoseconds: 46488

From thepace's algorithm onwards, the benchmarks run too fast to be effective. Using a 1000 trials:

Algorithm: wei2912's algorithm
Average time per trial (ns): 1453715507
Algorithm: Alnitak's algorithm
Average time per trial (ns): 1030910880
Algorithm: wei2912's algorithm
Average time per trial (ns): 12073
Algorithm: Alnitak's algorithm
Average time per trial (ns): 8602

Algorithm: wei2912's algorithm Average time per trial (ns): 12337 Algorithm: Alnitak's algorithm Average time per trial (ns): 7661

Alnitak's algorithm appears to be nearly 2 times faster. Great job to Alnitak! :)

Alnitak's algorithm:

Algorithm: Alnitak's algorithm
Time required to calculate in nanoseconds: 47100

My algorithm:

Algorithm: wei2912's algorithm
Time required to calculate in nanoseconds: 46488

From thepace's algorithm onwards, the benchmarks run too fast to be effective. Using a 1000 trials:

Algorithm: wei2912's algorithm
Average time per trial (ns): 14537
Algorithm: Alnitak's algorithm
Average time per trial (ns): 10309
Algorithm: wei2912's algorithm
Average time per trial (ns): 12073
Algorithm: Alnitak's algorithm
Average time per trial (ns): 8602

Alnitak's algorithm appears to be 2 times faster. Great job to Alnitak! :)

From thepace's algorithm onwards, the benchmarks run too fast to be effective. Using 1000 trials:

Algorithm: wei2912's algorithm
Average time per trial (ns): 15507
Algorithm: Alnitak's algorithm
Average time per trial (ns): 10880

Algorithm: wei2912's algorithm Average time per trial (ns): 12337 Algorithm: Alnitak's algorithm Average time per trial (ns): 7661

Alnitak's algorithm appears to be nearly 2 times faster. Great job to Alnitak! :)

added 171 characters in body
Source Link
wei2912
  • 1.3k
  • 8
  • 26

Alnitak's algorithm also needs to be corrected.:

Algorithm: Alnitak's algorithm
Time required to calculate in nanoseconds: 47100
ResultAlgorithm: 6857wei2912's algorithm
Time required to calculate in nanoseconds: 10775546488

From thepace's algorithm onwards, the algorithmsbenchmarks run too fast to be used as benchmarkseffective. Using a 1000 trials:

Algorithm: wei2912's algorithm
Average time per trial (ns): 14537
Algorithm: Alnitak's algorithm
Average time per trial (ns): 10309

Looks like Alnitak's algorithm is faster.

Generating a million random ints and feeding them into my algorithmin:

Algorithm: wei2912's algorithm
Average time per trial (ns): 1528712073
Algorithm: Alnitak's algorithm
Average time per trial (ns): 8602

Alnitak's algorithm appears to be 2 times faster. Great job to Alnitak! :)

I'd be glad to accept any suggestions for benchmarks.

Alnitak's algorithm also needs to be corrected.

Result: 6857
Time required to calculate in nanoseconds: 107755

From thepace's algorithm onwards, the algorithms run too fast to be used as benchmarks.

Generating a million random ints and feeding them into my algorithm:

Algorithm: wei2912's algorithm
Average time per trial (ns): 15287

Alnitak's algorithm:

Algorithm: Alnitak's algorithm
Time required to calculate in nanoseconds: 47100
Algorithm: wei2912's algorithm
Time required to calculate in nanoseconds: 46488

From thepace's algorithm onwards, the benchmarks run too fast to be effective. Using a 1000 trials:

Algorithm: wei2912's algorithm
Average time per trial (ns): 14537
Algorithm: Alnitak's algorithm
Average time per trial (ns): 10309

Looks like Alnitak's algorithm is faster.

Generating a million random ints and feeding them in:

Algorithm: wei2912's algorithm
Average time per trial (ns): 12073
Algorithm: Alnitak's algorithm
Average time per trial (ns): 8602

Alnitak's algorithm appears to be 2 times faster. Great job to Alnitak! :)

I'd be glad to accept any suggestions for benchmarks.

Remove benchmarks as the other 2 fast algorithms are found to have an error in them.
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Add Altinak's algorithm benchmarks.
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Fix a few typos.
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Throw in a further optimization.
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Clear up a few holes in the explanation.
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Fix slight typo and grant community wiki.; Post Made Community Wiki
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Optimize Haskell solution.
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Fix mistake in trace.
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Add in benchmarks of all algorithms posted in this question.
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Update haskell version.
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
added 3 characters in body
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Fix a typo.
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
add very informal benchmark
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading
Source Link
wei2912
  • 1.3k
  • 8
  • 26
Loading