#!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))) require 'wordlist' require 'benchmark' require 'fileutils' path = File.expand_path(File.join(File.dirname(__FILE__),'shakespeare_wordlist.txt')) FileUtils.rm_f(path) Benchmark.bm do |bm| bm.report('build') do Wordlist::Builder.build(path) do |wordlist| wordlist.parse_file('/home/hal/shaks12.txt') end end bm.report('each_unique') do Wordlist::FlatFile.new(path) do |wordlist| wordlist.each_unique { |word| word } end end bm.report('each_mutation (1)') do Wordlist::FlatFile.new(path) do |wordlist| wordlist.mutate /o/i, '0' wordlist.each_mutation { |word| word } end end bm.report('each_mutation (2)') do Wordlist::FlatFile.new(path) do |wordlist| wordlist.mutate /o/i, '0' wordlist.mutate /a/i, '@' wordlist.each_mutation { |word| word } end end bm.report('each_mutation (3)') do Wordlist::FlatFile.new(path) do |wordlist| wordlist.mutate /o/i, '0' wordlist.mutate /a/i, '@' wordlist.mutate /e/i, '3' wordlist.each_mutation { |word| word } end end end Benchmark.bm do |bm| mutator = Wordlist::Mutator.new(/o/i, '0') bm.report('Mutator#each') do mutator.each('lololololoLOLOLOLOLO') { |word| } end end