Skip to content

Instantly share code, notes, and snippets.

@jodosha
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jodosha/55bafdd83a89741258fd to your computer and use it in GitHub Desktop.
Save jodosha/55bafdd83a89741258fd to your computer and use it in GitHub Desktop.
Lotus::Utils::String#pluralize vs ActiveSupport String#pluralize
#!/usr/bin/env ruby
$:.unshift 'lib'
require 'benchmark/ips'
require 'lotus/utils/string'
require 'active_support/all'
GC.disable
TEST_PLURALS = {
"murex" => "murices",
"silex" => "silices",
"apex" => "apices",
"latex" => "latices",
"vertex" => "vertices",
"cortex" => "cortices",
"pontifex" => "pontifices",
"vortex" => "vortices",
"index" => "indices",
"simplex" => "simplices",
"helix" => "helices",
"appendix" => "appendices",
"bacterium" => "bacteria",
"agendum" => "agenda",
"desideratum" => "desiderata",
"erratum" => "errata",
"stratum" => "strata",
"datum" => "data",
"ovum" => "ova",
"extremum" => "extrema",
"candelabrum" => "candelabra",
"curriculum" => "curricula",
"millennium" => "millennia",
"referendum" => "referenda",
"stadium" => "stadia",
"medium" => "media",
"memorandum" => "memoranda",
"alumnus" => "alumni",
"alveolus" => "alveoli",
"bacillus" => "bacilli",
"bronchus" => "bronchi",
"locus" => "loci",
"nucleus" => "nuclei",
"stimulus" => "stimuli",
"meniscus" => "menisci",
"thesaurus" => "thesauri",
"criterion" => "criteria",
"perihelion" => "perihelia",
"aphelion" => "aphelia",
"phenomenon" => "phenomena",
"prolegomenon" => "prolegomena",
"noumenon" => "noumena",
"organon" => "organa",
"asyndeton" => "asyndeta",
"hyperbaton" => "hyperbata",
"alumna" => "alumnae",
"alga" => "algae",
"vertebra" => "vertebrae",
"persona" => "personae",
"antenna" => "antennae",
"formula" => "formulae",
"nebula" => "nebulae",
"vita" => "vitae",
"albino" => "albinos",
"archipelago" => "archipelagos",
"armadillo" => "armadillos",
"commando" => "commandos",
"crescendo" => "crescendos",
"fiasco" => "fiascos",
"ditto" => "dittos",
"dynamo" => "dynamos",
"embryo" => "embryos",
"ghetto" => "ghettos",
"guano" => "guanos",
"inferno" => "infernos",
"jumbo" => "jumbos",
"lumbago" => "lumbagos",
"magneto" => "magnetos",
"manifesto" => "manifestos",
"medico" => "medicos",
"octavo" => "octavos",
"photo" => "photos",
"pro" => "pros",
"quarto" => "quartos",
"canto" => "cantos",
"lingo" => "lingos",
"generalissimo" => "generalissimos",
"stylo" => "stylos",
"rhino" => "rhinos",
"casino" => "casinos",
"auto" => "autos",
"macro" => "macros",
"zero" => "zeros",
"todo" => "todos",
"studio" => "studios",
"avocado" => "avocados",
"zoo" => "zoos",
"banjo" => "banjos",
"cargo" => "cargos",
"flamingo" => "flamingos",
"fresco" => "frescos",
"halo" => "halos",
"mango" => "mangos",
"memento" => "mementos",
"motto" => "mottos",
"tornado" => "tornados",
"tuxedo" => "tuxedos",
"volcano" => "volcanos",
"solo" => "solos",
"soprano" => "sopranos",
"basso" => "bassos",
"alto" => "altos",
"contralto" => "contraltos",
"tempo" => "tempos",
"piano" => "pianos",
"virtuoso" => "virtuosos",
"buffalo" => "buffaloes",
"domino" => "dominoes",
"echo" => "echoes",
"embargo" => "embargoes",
"hero" => "heroes",
"mosquito" => "mosquitoes",
"potato" => "potatoes",
"tomato" => "tomatoes",
"torpedo" => "torpedoes",
"veto" => "vetoes",
"stamen" => "stamina",
"foramen" => "foramina",
"lumen" => "lumina",
"anathema" => "anathemata",
"enema" => "enemata",
"oedema" => "oedemata",
"bema" => "bemata",
"enigma" => "enigmata",
"sarcoma" => "sarcomata",
"carcinoma" => "carcinomata",
"gumma" => "gummata",
"schema" => "schemata",
"charisma" => "charismata",
"lemma" => "lemmata",
"soma" => "somata",
"diploma" => "diplomata",
"lymphoma" => "lymphomata",
"stigma" => "stigmata",
"dogma" => "dogmata",
"magma" => "magmata",
"stoma" => "stomata",
"drama" => "dramata",
"melisma" => "melismata",
"trauma" => "traumata",
"edema" => "edemata",
"miasma" => "miasmata",
"iris" => "irides",
"clitoris" => "clitorides",
"axis" => "axes",
"analysis" => "analyses",
"basis" => "bases",
"crisis" => "crises",
"diagnosis" => "diagnoses",
"ellipsis" => "ellipses",
"hypothesis" => "hypotheses",
"oasis" => "oases",
"paralysis" => "paralyses",
"parenthesis" => "parentheses",
"synthesis" => "syntheses",
"synopsis" => "synopses",
"thesis" => "theses",
"apparatus" => "apparatuses",
"impetus" => "impetuses",
"prospectus" => "prospectuses",
"cantus" => "cantuses",
"nexus" => "nexuses",
"sinus" => "sinuses",
"coitus" => "coituses",
"plexus" => "plexuses",
"status" => "statuses",
"hiatus" => "hiatuses",
"bus" => "buses",
"octopus" => "octopuses",
"acropolis" => "acropolises",
"chaos" => "chaoses",
"lens" => "lenses",
"aegis" => "aegises",
"cosmos" => "cosmoses",
"mantis" => "mantises",
"alias" => "aliases",
"dais" => "daises",
"marquis" => "marquises",
"asbestos" => "asbestoses",
"digitalis" => "digitalises",
"metropolis" => "metropolises",
"atlas" => "atlases",
"epidermis" => "epidermises",
"pathos" => "pathoses",
"bathos" => "bathoses",
"ethos" => "ethoses",
"pelvis" => "pelvises",
"bias" => "biases",
"gas" => "gases",
"polis" => "polises",
"caddis" => "caddises",
"rhinoceros" => "rhinoceroses",
"cannabis" => "cannabises",
"glottis" => "glottises",
"sassafras" => "sassafrases",
"canvas" => "canvases",
"ibis" => "ibises",
"trellis" => "trellises",
"kiss" => "kisses",
"human" => "humans",
"Alabaman" => "Alabamans",
"Bahaman" => "Bahamans",
"Burman" => "Burmans",
"German" => "Germans",
"Hiroshiman" => "Hiroshimans",
"Liman" => "Limans",
"Nakayaman" => "Nakayamans",
"Oklahoman" => "Oklahomans",
"Panaman" => "Panamans",
"Selman" => "Selmans",
"Sonaman" => "Sonamans",
"Tacoman" => "Tacomans",
"Yakiman" => "Yakimans",
"Yokohaman" => "Yokohamans",
"Yuman" => "Yumans",
"witch" => "witches",
"church" => "churches",
"stomach" => "stomachs",
"epoch" => "epochs",
"box" => "boxes",
"fox" => "foxes",
"boy" => "boys",
"way" => "ways",
"buy" => "buys",
"baby" => "babies",
"lorry" => "lorries",
"entity" => "entities",
"repository" => "repositories",
"fly" => "flies",
"leaf" => "leaves",
"hoof" => "hooves",
"self" => "selves",
"elf" => "elves",
"half" => "halves",
"scarf" => "scarves",
"dwarf" => "dwarves",
"chief" => "chiefs",
"spoof" => "spoofs",
"knife" => "knives",
"life" => "lives",
"wife" => "wives",
"beau" => "beaux",
"bureau" => "bureaux",
"tableau" => "tableaux",
"louse" => "lice",
"mouse" => "mice",
"cactus" => "cacti",
"foot" => "feet",
"tooth" => "teeth",
"goose" => "geese",
"child" => "children",
"man" => "men",
"woman" => "women",
"person" => "people",
"ox" => "oxen",
"corpus" => "corpora",
"genus" => "genera",
"sex" => "sexes",
"quiz" => "quizzes",
"testis" => "testes",
"deer" => "deer",
"fish" => "fish",
"money" => "money",
"means" => "means",
"offspring" => "offspring",
"series" => "series",
"sheep" => "sheep",
"species" => "species",
"equipment" => "equipment",
"information" => "information",
"rice" => "rice",
"news" => "news",
"test" => "tests",
"feature" => "features",
"fixture" => "fixtures",
"controller" => "controllers",
"action" => "actions",
"router" => "routers",
"route" => "routes",
"endpoint" => "endpoints",
"string" => "strings",
"view" => "views",
"template" => "templates",
"layout" => "layouts",
"application" => "applications",
"api" => "apis",
"model" => "models",
"mapper" => "mappers",
"mapping" => "mappings",
"table" => "tables",
"attribute" => "attributes",
"column" => "columns",
"migration" => "migrations",
"presenter" => "presenters",
"wizard" => "wizards",
"architecture" => "architectures",
"cat" => "cats",
"car" => "cars",
"hive" => "hives",
"giraffe" => "giraffes",
}.freeze
size = TEST_PLURALS.size
utils_misses = 0
as_misses = 0
TEST_PLURALS.each do |singular, plural|
unless Lotus::Utils::String.new(singular).pluralize == plural
utils_misses += 1
end
end
TEST_PLURALS.each do |singular, plural|
unless singular.pluralize == plural
as_misses += 1
end
end
puts "Lotus::Utils::String missed #{ utils_misses }/#{ size } words"
puts "ActiveSupport missed #{ as_misses }/#{ size } words"
Benchmark.ips do |x|
x.report('utils') { TEST_PLURALS.each {|word,_| Lotus::Utils::String.new(word).pluralize } }
x.report('AS') { TEST_PLURALS.each {|word,_| word.pluralize } }
end
__END__
Output:
Lotus::Utils::String missed 0/300 words
ActiveSupport missed 148/300 words
Calculating -------------------------------------
utils 8.000 i/100ms
AS 20.000 i/100ms
-------------------------------------------------
utils 82.743 (± 2.4%) i/s - 416.000
AS 199.489 (± 4.5%) i/s - 1.000k
Ruby:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
Hardware:
Hardware Overview:
Model Name: MacBook Pro
Model Identifier: MacBookPro12,1
Processor Name: Intel Core i7
Processor Speed: 3,1 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache (per Core): 256 KB
L3 Cache: 4 MB
Memory: 16 GB
Boot ROM Version: MBP121.0167.B00
SMC Version (system): 2.28f6
Software:
System Software Overview:
System Version: OS X 10.10.2 (14C2513)
Kernel Version: Darwin 14.1.1
Time since boot: 25 days 3:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment