openlogic / random-word

MIT License
27 stars 15 forks source link

Switch from Marshall to JSON, remove offensive words #10

Closed lostapathy closed 6 years ago

lostapathy commented 6 years ago

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:

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

Results on ruby 2.4.2

Warming up --------------------------------------
             marshal     5.000  i/100ms
                JSON     5.000  i/100ms
Calculating -------------------------------------
             marshal     58.304  (± 3.4%) i/s -    295.000  in   5.065606s
                JSON     56.292  (± 1.8%) i/s -    285.000  in   5.064321s

Comparison:
             marshal:       58.3 i/s
                JSON:       56.3 i/s - same-ish: difference falls within error

Surprisingly, when I tested it against ruby 2.1.10, JSON was substantially faster:

Comparison:
                JSON:       56.1 i/s
             marshal:       30.3 i/s - 1.86x  slower

Then I simply removed all the words in the list linked on #9 from the JSON file (except "crazy", that seems ok).

coveralls commented 6 years ago

Coverage Status

Changes Unknown when pulling 01e69e5b814e3343f58c0d650d0e77e5f8bed6f2 on lostapathy:switch_to_json into on openlogic:master.

pezra commented 6 years ago

@toddthomas can you merge this (or give me commit rights)

toddthomas commented 6 years ago

@pezra you should have an invite to be a contributor with commit rights. @lostapathy thank you!