scsmith/language_list — pull request #5 by jrochkind (2013-03-08 20:48:35+00:00)
Title: Global hashes for performance

So I left all the existing Arrays in there, because I guess they are part of the api now.

But adding global hashes for lookup speeds up lookup rather tremendously as one would probably expect vs scanning a ~10k array.

[Here's the benchmark I created](https://github.com/jrochkind/language_list/blob/global_hashes/test/benchmark_lookup.rb), trying to look up 1000 random languages by both name and id, 1000 tries. For the hash version, the time it takes is virtually unmeasurable.

Current master:

1.580000 0.000000 1.580000 ( 1.589537)

global_hashes branch:

0.000000 0.000000 0.000000 ( 0.002096)

The global_hashes branch does slightly increase the load time. It looks like about 10-20 ms, hardly anything. I'm not going to put in exact numbers, because the benchmark on load varies every time I run it, but it seemed to generally be 40-80ms in global_hashes branch, and 20-50ms in current master. Benchmarking reliably is hard! But anyway, while the hash lookup makes the load _slightly_ slower, I don't think it's significantly so, and worth it for tremendously faster lookup.