First, I changed the data repository from Marshal to JSON, so that it's more easily edited. Marshal also isn't guaranteed to work between ruby versions, so this makes us more future-proof and (probably) more tolerant of different rubies.
I ran a benchmark to verify we weren't hurting anything:
require 'benchmark/ips'
require 'json'
Benchmark.ips do |x|
x.report("marshal") { Marshal.load(File.read('data/nouns.dat')) }
x.report("JSON") { JSON.parse(File.read('data/nouns.json')) }
x.compare!
end
This resolves #9
First, I changed the data repository from Marshal to JSON, so that it's more easily edited. Marshal also isn't guaranteed to work between ruby versions, so this makes us more future-proof and (probably) more tolerant of different rubies.
I ran a benchmark to verify we weren't hurting anything:
Results on ruby 2.4.2
Surprisingly, when I tested it against ruby 2.1.10, JSON was substantially faster:
Then I simply removed all the words in the list linked on #9 from the JSON file (except "crazy", that seems ok).