# Problem with arrays

Hello,

I’m coding a program which implements the levenshtein distance between
two
strings. It works, but very slowly.

I discover that the slowest line in the code is:

current[j] = m

where current is an array of Fixnum, and m is a Fixnum.

If i comment this line the program runs about 50 times faster.
If I change it to any other thing, like “current[j] = 1” it still
running
fast.

I can’t understand why “current[j] = 1” is faster than “current[j] = m”.

Thanks,

Michel B.

Michel B. wrote:

I discover that the slowest line in the code is:

current[j] = m

where current is an array of Fixnum, and m is a Fixnum.

If i comment this line the program runs about 50 times faster.
If I change it to any other thing, like “current[j] = 1” it still
running
fast.

I can’t understand why “current[j] = 1” is faster than “current[j] = m”.

As far as I can tell, it is not faster.

n = 10_000_000

start_time = Time.now
intarr = [1, 2, 3]
n.times {intarr = n}
p Time.now - start_time

start_time = Time.now
intarr = [1, 2, 3]
n.times {intarr = 5}
p Time.now - start_time

result:
3.438
3.437

Opened http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=3314.
That’s wacky! Doesn’t happen if you remove the last or first item …
it’s gonna be fun to track that down. =)