Skip to content

Commit

Permalink
example: use fast aref - no bounds checks
Browse files Browse the repository at this point in the history
res at(i) 6m20s
res(i)    11s
res[i]    7s

at(i) is so slow, because we dont have the method cache yet
  • Loading branch information
Reini Urban committed Feb 25, 2016
1 parent cc4cc14 commit de1c5b3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions example/100thoddprime.pn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# very slow potion, compared to ruby.
# very slow potion aref method call, compared to ruby.
# 6m30s in the jit, compared to 30s with ruby
# written by Kokizzu
# https://stackoverflow.com/questions/29091475/printing-odd-prime-every-100k-primes-found/
Expand All @@ -10,7 +10,9 @@ loop:
len = res length
i = 0
while(i<len):
v = res at(i)
#v = res at(i) # slow 6m30s
#v = res(i) # 11s
v = res[i] # 7s - no bounds checks
if(v*v > last): break.
if(last%v == 0): prime = false, break.
i += 1
Expand Down

0 comments on commit de1c5b3

Please sign in to comment.