From 911d5e374f10fa042f45c2d8b0fc9f58fcbbe6d5 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Wed, 11 Feb 2015 22:41:59 -0800 Subject: [PATCH] Add benchmark for string map keys. --- benchmark/{maps.lua => map_numeric.lua} | 6 +- benchmark/{maps.py => map_numeric.py} | 10 +-- benchmark/{maps.rb => map_numeric.rb} | 10 +-- benchmark/{maps.wren => map_numeric.wren} | 6 +- benchmark/map_string.lua | 98 +++++++++++++++++++++++ benchmark/map_string.py | 96 ++++++++++++++++++++++ benchmark/map_string.rb | 98 +++++++++++++++++++++++ benchmark/map_string.wren | 98 +++++++++++++++++++++++ script/benchmark.py | 4 +- 9 files changed, 409 insertions(+), 17 deletions(-) rename benchmark/{maps.lua => map_numeric.lua} (76%) rename benchmark/{maps.py => map_numeric.py} (54%) rename benchmark/{maps.rb => map_numeric.rb} (70%) rename benchmark/{maps.wren => map_numeric.wren} (69%) create mode 100644 benchmark/map_string.lua create mode 100644 benchmark/map_string.py create mode 100644 benchmark/map_string.rb create mode 100644 benchmark/map_string.wren mode change 100644 => 100755 script/benchmark.py diff --git a/benchmark/maps.lua b/benchmark/map_numeric.lua similarity index 76% rename from benchmark/maps.lua rename to benchmark/map_numeric.lua index 8e3f428d..e6d43d07 100644 --- a/benchmark/maps.lua +++ b/benchmark/map_numeric.lua @@ -2,17 +2,17 @@ local start = os.clock() local map = {} -for i = 1, 100000 do +for i = 1, 1000000 do map[i] = i end local sum = 0 -for i = 1, 100000 do +for i = 1, 1000000 do sum = sum + map[i] end io.write(string.format("%d\n", sum)) -for i = 1, 100000 do +for i = 1, 1000000 do map[i] = nil end diff --git a/benchmark/maps.py b/benchmark/map_numeric.py similarity index 54% rename from benchmark/maps.py rename to benchmark/map_numeric.py index 6d4a8782..8b90ec14 100644 --- a/benchmark/maps.py +++ b/benchmark/map_numeric.py @@ -2,19 +2,19 @@ from __future__ import print_function import time -map = {} - start = time.clock() -for i in range(1, 100001): +map = {} + +for i in range(1, 1000001): map[i] = i sum = 0 -for i in range(1, 100001): +for i in range(1, 1000001): sum = sum + map[i] print(sum) -for i in range(1, 100001): +for i in range(1, 1000001): del map[i] print("elapsed: " + str(time.clock() - start)) \ No newline at end of file diff --git a/benchmark/maps.rb b/benchmark/map_numeric.rb similarity index 70% rename from benchmark/maps.rb rename to benchmark/map_numeric.rb index 284d7405..eaf25631 100644 --- a/benchmark/maps.rb +++ b/benchmark/map_numeric.rb @@ -1,18 +1,18 @@ -map = Hash.new - start = Time.now -for i in (1..100000) +map = Hash.new + +for i in (1..1000000) map[i] = i end sum = 0 -for i in (1..100000) +for i in (1..1000000) sum = sum + map[i] end puts sum -for i in (1..100000) +for i in (1..1000000) map.delete(i) end diff --git a/benchmark/maps.wren b/benchmark/map_numeric.wren similarity index 69% rename from benchmark/maps.wren rename to benchmark/map_numeric.wren index cf8bac5b..b07b5fe2 100644 --- a/benchmark/maps.wren +++ b/benchmark/map_numeric.wren @@ -2,17 +2,17 @@ var start = IO.clock var map = {} -for (i in 1..100000) { +for (i in 1..1000000) { map[i] = i } var sum = 0 -for (i in 1..100000) { +for (i in 1..1000000) { sum = sum + map[i] } IO.print(sum) -for (i in 1..100000) { +for (i in 1..1000000) { map.remove(i) } diff --git a/benchmark/map_string.lua b/benchmark/map_string.lua new file mode 100644 index 00000000..4c972987 --- /dev/null +++ b/benchmark/map_string.lua @@ -0,0 +1,98 @@ +local adverbs = { + "moderately", "really", "slightly", "very" +} + +local adjectives = { + "abandoned", "able", "absolute", "academic", "acceptable", "acclaimed", + "accomplished", "accurate", "aching", "acidic", "acrobatic", "active", + "actual", "adept", "admirable", "admired", "adolescent", "adorable", "adored", + "advanced", "adventurous", "affectionate", "afraid", "aged", "aggravating", + "aggressive", "agile", "agitated", "agonizing", "agreeable", "ajar", + "alarmed", "alarming", "alert", "alienated", "alive", "all", "altruistic", + "amazing", "ambitious", "ample", "amused", "amusing", "anchored", "ancient", + "angelic", "angry", "anguished", "animated", "annual", "another", "antique", + "anxious", "any", "apprehensive", "appropriate", "apt", "arctic", "arid", + "aromatic", "artistic", "ashamed", "assured", "astonishing", "athletic", + "attached", "attentive", "attractive", "austere", "authentic", "authorized", + "automatic", "avaricious", "average", "aware", "awesome", "awful", "awkward", + "babyish", "back", "bad", "baggy", "bare", "barren", "basic", "beautiful", + "belated", "beloved", "beneficial", "best", "better", "bewitched", "big", + "big-hearted", "biodegradable", "bite-sized", "bitter", "black", + "black-and-white", "bland", "blank", "blaring", "bleak", "blind", "blissful", + "blond", "blue", "blushing", "bogus", "boiling", "bold", "bony", "boring", + "bossy", "both", "bouncy", "bountiful", "bowed", "brave", "breakable", + "brief", "bright", "brilliant", "brisk", "broken", "bronze", "brown", + "bruised", "bubbly", "bulky", "bumpy", "buoyant", "burdensome", "burly", + "bustling", "busy", "buttery", "buzzing", "calculating", "calm", "candid", + "canine", "capital", "carefree", "careful", "careless", "caring", "cautious", + "cavernous", "celebrated", "charming", "cheap", "cheerful", "cheery", "chief", + "chilly", "chubby", "circular", "classic", "clean", "clear", "clear-cut", + "clever", "close", "closed", "cloudy", "clueless", "clumsy", "cluttered", + "coarse", "cold", "colorful", "colorless", "colossal", "comfortable", + "common", "compassionate", "competent", "complete", "complex", "complicated", + "composed", "concerned", "concrete", "confused", "conscious", "considerate", + "constant", "content", "conventional", "cooked", "cool", "cooperative", + "coordinated", "corny", "corrupt", "costly", "courageous", "courteous", + "crafty" +} + +local animals = { + "aardvark", "african buffalo", "albatross", "alligator", "alpaca", "ant", + "anteater", "antelope", "ape", "armadillo", "baboon", "badger", "barracuda", + "bat", "bear", "beaver", "bee", "bison", "black panther", "blue jay", "boar", + "butterfly", "camel", "capybara", "carduelis", "caribou", "cassowary", "cat", + "caterpillar", "cattle", "chamois", "cheetah", "chicken", "chimpanzee", + "chinchilla", "chough", "clam", "cobra", "cockroach", "cod", "cormorant", + "coyote", "crab", "crane", "crocodile", "crow", "curlew", "deer", "dinosaur", + "dog", "dolphin", "domestic pig", "donkey", "dotterel", "dove", "dragonfly", + "duck", "dugong", "dunlin", "eagle", "echidna", "eel", "elephant seal", + "elephant", "elk", "emu", "falcon", "ferret", "finch", "fish", "flamingo", + "fly", "fox", "frog", "gaur", "gazelle", "gerbil", "giant panda", "giraffe", + "gnat", "goat", "goldfish", "goose", "gorilla", "goshawk", "grasshopper", + "grouse", "guanaco", "guinea fowl", "guinea pig", "gull", "hamster", "hare", + "hawk", "hedgehog", "heron", "herring", "hippopotamus", "hornet", "horse", + "human", "hummingbird", "hyena", "ibex", "ibis", "jackal", "jaguar", "jay", + "jellyfish", "kangaroo", "kingfisher", "koala", "komodo dragon", "kookabura", + "kouprey", "kudu", "lapwing", "lark", "lemur", "leopard", "lion", "llama", + "lobster", "locust", "loris", "louse", "lyrebird", "magpie", "mallard", + "manatee", "mandrill", "mantis", "marten", "meerkat", "mink", "mole", + "mongoose", "monkey", "moose", "mosquito", "mouse", "mule", "narwhal", "newt", + "nightingale", "octopus", "okapi", "opossum", "oryx", "ostrich", "otter", + "owl", "oyster", "parrot", "partridge", "peafowl", "pelican", "penguin", + "pheasant", "pigeon", "pinniped", "polar bear", "pony", "porcupine", + "porpoise", "prairie dog", "quail", "quelea", "quetzal", "rabbit", "raccoon", + "ram", "rat", "raven", "red deer", "red panda", "reindeer", "rhinoceros", + "rook", "salamander", "salmon", "sand dollar", "sandpiper", "sardine", + "scorpion", "sea lion", "sea urchin", "seahorse", "shark", "sheep", "shrew", + "skunk", "snail", "snake", "sparrow", "spider", "spoonbill", "squid", + "wallaby", "wildebeest" +} + +local keys = {} +for _, animal in ipairs(animals) do + for _, adjective in ipairs(adjectives) do + for _, adverb in ipairs(adverbs) do + table.insert(keys, adverb .. " " .. adjective .. " " .. animal) + end + end +end + +local start = os.clock() + +local map = {} + +for _, key in ipairs(keys) do + map[key] = string.len(key) +end + +local sum = 0 +for _, key in ipairs(keys) do + sum = sum + map[key] +end + +for _, key in ipairs(keys) do + map[key] = nil +end + +io.write(string.format("%d\n", sum)) +io.write(string.format("elapsed: %.8f\n", os.clock() - start)) diff --git a/benchmark/map_string.py b/benchmark/map_string.py new file mode 100644 index 00000000..4e2c8d31 --- /dev/null +++ b/benchmark/map_string.py @@ -0,0 +1,96 @@ +from __future__ import print_function + +import time + +adverbs = [ + "moderately", "really", "slightly", "very" +] + +adjectives = [ + "abandoned", "able", "absolute", "academic", "acceptable", "acclaimed", + "accomplished", "accurate", "aching", "acidic", "acrobatic", "active", + "actual", "adept", "admirable", "admired", "adolescent", "adorable", "adored", + "advanced", "adventurous", "affectionate", "afraid", "aged", "aggravating", + "aggressive", "agile", "agitated", "agonizing", "agreeable", "ajar", + "alarmed", "alarming", "alert", "alienated", "alive", "all", "altruistic", + "amazing", "ambitious", "ample", "amused", "amusing", "anchored", "ancient", + "angelic", "angry", "anguished", "animated", "annual", "another", "antique", + "anxious", "any", "apprehensive", "appropriate", "apt", "arctic", "arid", + "aromatic", "artistic", "ashamed", "assured", "astonishing", "athletic", + "attached", "attentive", "attractive", "austere", "authentic", "authorized", + "automatic", "avaricious", "average", "aware", "awesome", "awful", "awkward", + "babyish", "back", "bad", "baggy", "bare", "barren", "basic", "beautiful", + "belated", "beloved", "beneficial", "best", "better", "bewitched", "big", + "big-hearted", "biodegradable", "bite-sized", "bitter", "black", + "black-and-white", "bland", "blank", "blaring", "bleak", "blind", "blissful", + "blond", "blue", "blushing", "bogus", "boiling", "bold", "bony", "boring", + "bossy", "both", "bouncy", "bountiful", "bowed", "brave", "breakable", + "brief", "bright", "brilliant", "brisk", "broken", "bronze", "brown", + "bruised", "bubbly", "bulky", "bumpy", "buoyant", "burdensome", "burly", + "bustling", "busy", "buttery", "buzzing", "calculating", "calm", "candid", + "canine", "capital", "carefree", "careful", "careless", "caring", "cautious", + "cavernous", "celebrated", "charming", "cheap", "cheerful", "cheery", "chief", + "chilly", "chubby", "circular", "classic", "clean", "clear", "clear-cut", + "clever", "close", "closed", "cloudy", "clueless", "clumsy", "cluttered", + "coarse", "cold", "colorful", "colorless", "colossal", "comfortable", + "common", "compassionate", "competent", "complete", "complex", "complicated", + "composed", "concerned", "concrete", "confused", "conscious", "considerate", + "constant", "content", "conventional", "cooked", "cool", "cooperative", + "coordinated", "corny", "corrupt", "costly", "courageous", "courteous", + "crafty" +] + +animals = [ + "aardvark", "african buffalo", "albatross", "alligator", "alpaca", "ant", + "anteater", "antelope", "ape", "armadillo", "baboon", "badger", "barracuda", + "bat", "bear", "beaver", "bee", "bison", "black panther", "blue jay", "boar", + "butterfly", "camel", "capybara", "carduelis", "caribou", "cassowary", "cat", + "caterpillar", "cattle", "chamois", "cheetah", "chicken", "chimpanzee", + "chinchilla", "chough", "clam", "cobra", "cockroach", "cod", "cormorant", + "coyote", "crab", "crane", "crocodile", "crow", "curlew", "deer", "dinosaur", + "dog", "dolphin", "domestic pig", "donkey", "dotterel", "dove", "dragonfly", + "duck", "dugong", "dunlin", "eagle", "echidna", "eel", "elephant seal", + "elephant", "elk", "emu", "falcon", "ferret", "finch", "fish", "flamingo", + "fly", "fox", "frog", "gaur", "gazelle", "gerbil", "giant panda", "giraffe", + "gnat", "goat", "goldfish", "goose", "gorilla", "goshawk", "grasshopper", + "grouse", "guanaco", "guinea fowl", "guinea pig", "gull", "hamster", "hare", + "hawk", "hedgehog", "heron", "herring", "hippopotamus", "hornet", "horse", + "human", "hummingbird", "hyena", "ibex", "ibis", "jackal", "jaguar", "jay", + "jellyfish", "kangaroo", "kingfisher", "koala", "komodo dragon", "kookabura", + "kouprey", "kudu", "lapwing", "lark", "lemur", "leopard", "lion", "llama", + "lobster", "locust", "loris", "louse", "lyrebird", "magpie", "mallard", + "manatee", "mandrill", "mantis", "marten", "meerkat", "mink", "mole", + "mongoose", "monkey", "moose", "mosquito", "mouse", "mule", "narwhal", "newt", + "nightingale", "octopus", "okapi", "opossum", "oryx", "ostrich", "otter", + "owl", "oyster", "parrot", "partridge", "peafowl", "pelican", "penguin", + "pheasant", "pigeon", "pinniped", "polar bear", "pony", "porcupine", + "porpoise", "prairie dog", "quail", "quelea", "quetzal", "rabbit", "raccoon", + "ram", "rat", "raven", "red deer", "red panda", "reindeer", "rhinoceros", + "rook", "salamander", "salmon", "sand dollar", "sandpiper", "sardine", + "scorpion", "sea lion", "sea urchin", "seahorse", "shark", "sheep", "shrew", + "skunk", "snail", "snake", "sparrow", "spider", "spoonbill", "squid", + "wallaby", "wildebeest" +] + +keys = [] +for animal in animals: + for adjective in adjectives: + for adverb in adverbs: + keys.append(adverb + " " + adjective + " " + animal) + +start = time.clock() + +map = {} + +for key in keys: + map[key] = len(key) + +sum = 0 +for key in keys: + sum = sum + map[key] + +for key in keys: + del map[key] + +print(sum) +print("elapsed: " + str(time.clock() - start)) diff --git a/benchmark/map_string.rb b/benchmark/map_string.rb new file mode 100644 index 00000000..2238fc92 --- /dev/null +++ b/benchmark/map_string.rb @@ -0,0 +1,98 @@ +adverbs = [ + "moderately", "really", "slightly", "very" +] + +adjectives = [ + "abandoned", "able", "absolute", "academic", "acceptable", "acclaimed", + "accomplished", "accurate", "aching", "acidic", "acrobatic", "active", + "actual", "adept", "admirable", "admired", "adolescent", "adorable", "adored", + "advanced", "adventurous", "affectionate", "afraid", "aged", "aggravating", + "aggressive", "agile", "agitated", "agonizing", "agreeable", "ajar", + "alarmed", "alarming", "alert", "alienated", "alive", "all", "altruistic", + "amazing", "ambitious", "ample", "amused", "amusing", "anchored", "ancient", + "angelic", "angry", "anguished", "animated", "annual", "another", "antique", + "anxious", "any", "apprehensive", "appropriate", "apt", "arctic", "arid", + "aromatic", "artistic", "ashamed", "assured", "astonishing", "athletic", + "attached", "attentive", "attractive", "austere", "authentic", "authorized", + "automatic", "avaricious", "average", "aware", "awesome", "awful", "awkward", + "babyish", "back", "bad", "baggy", "bare", "barren", "basic", "beautiful", + "belated", "beloved", "beneficial", "best", "better", "bewitched", "big", + "big-hearted", "biodegradable", "bite-sized", "bitter", "black", + "black-and-white", "bland", "blank", "blaring", "bleak", "blind", "blissful", + "blond", "blue", "blushing", "bogus", "boiling", "bold", "bony", "boring", + "bossy", "both", "bouncy", "bountiful", "bowed", "brave", "breakable", + "brief", "bright", "brilliant", "brisk", "broken", "bronze", "brown", + "bruised", "bubbly", "bulky", "bumpy", "buoyant", "burdensome", "burly", + "bustling", "busy", "buttery", "buzzing", "calculating", "calm", "candid", + "canine", "capital", "carefree", "careful", "careless", "caring", "cautious", + "cavernous", "celebrated", "charming", "cheap", "cheerful", "cheery", "chief", + "chilly", "chubby", "circular", "classic", "clean", "clear", "clear-cut", + "clever", "close", "closed", "cloudy", "clueless", "clumsy", "cluttered", + "coarse", "cold", "colorful", "colorless", "colossal", "comfortable", + "common", "compassionate", "competent", "complete", "complex", "complicated", + "composed", "concerned", "concrete", "confused", "conscious", "considerate", + "constant", "content", "conventional", "cooked", "cool", "cooperative", + "coordinated", "corny", "corrupt", "costly", "courageous", "courteous", + "crafty" +] + +animals = [ + "aardvark", "african buffalo", "albatross", "alligator", "alpaca", "ant", + "anteater", "antelope", "ape", "armadillo", "baboon", "badger", "barracuda", + "bat", "bear", "beaver", "bee", "bison", "black panther", "blue jay", "boar", + "butterfly", "camel", "capybara", "carduelis", "caribou", "cassowary", "cat", + "caterpillar", "cattle", "chamois", "cheetah", "chicken", "chimpanzee", + "chinchilla", "chough", "clam", "cobra", "cockroach", "cod", "cormorant", + "coyote", "crab", "crane", "crocodile", "crow", "curlew", "deer", "dinosaur", + "dog", "dolphin", "domestic pig", "donkey", "dotterel", "dove", "dragonfly", + "duck", "dugong", "dunlin", "eagle", "echidna", "eel", "elephant seal", + "elephant", "elk", "emu", "falcon", "ferret", "finch", "fish", "flamingo", + "fly", "fox", "frog", "gaur", "gazelle", "gerbil", "giant panda", "giraffe", + "gnat", "goat", "goldfish", "goose", "gorilla", "goshawk", "grasshopper", + "grouse", "guanaco", "guinea fowl", "guinea pig", "gull", "hamster", "hare", + "hawk", "hedgehog", "heron", "herring", "hippopotamus", "hornet", "horse", + "human", "hummingbird", "hyena", "ibex", "ibis", "jackal", "jaguar", "jay", + "jellyfish", "kangaroo", "kingfisher", "koala", "komodo dragon", "kookabura", + "kouprey", "kudu", "lapwing", "lark", "lemur", "leopard", "lion", "llama", + "lobster", "locust", "loris", "louse", "lyrebird", "magpie", "mallard", + "manatee", "mandrill", "mantis", "marten", "meerkat", "mink", "mole", + "mongoose", "monkey", "moose", "mosquito", "mouse", "mule", "narwhal", "newt", + "nightingale", "octopus", "okapi", "opossum", "oryx", "ostrich", "otter", + "owl", "oyster", "parrot", "partridge", "peafowl", "pelican", "penguin", + "pheasant", "pigeon", "pinniped", "polar bear", "pony", "porcupine", + "porpoise", "prairie dog", "quail", "quelea", "quetzal", "rabbit", "raccoon", + "ram", "rat", "raven", "red deer", "red panda", "reindeer", "rhinoceros", + "rook", "salamander", "salmon", "sand dollar", "sandpiper", "sardine", + "scorpion", "sea lion", "sea urchin", "seahorse", "shark", "sheep", "shrew", + "skunk", "snail", "snake", "sparrow", "spider", "spoonbill", "squid", + "wallaby", "wildebeest" +] + +keys = [] +for animal in animals + for adjective in adjectives + for adverb in adverbs + keys << adverb + " " + adjective + " " + animal + end + end +end + +start = Time.now + +map = Hash.new + +for key in keys + map[key] = key.length +end + +sum = 0 +for key in keys + sum = sum + map[key] +end + +for key in keys + map.delete(key) +end + +puts sum +puts "elapsed: " + (Time.now - start).to_s diff --git a/benchmark/map_string.wren b/benchmark/map_string.wren new file mode 100644 index 00000000..12e3c024 --- /dev/null +++ b/benchmark/map_string.wren @@ -0,0 +1,98 @@ +var adverbs = [ + "moderately", "really", "slightly", "very" +] + +var adjectives = [ + "abandoned", "able", "absolute", "academic", "acceptable", "acclaimed", + "accomplished", "accurate", "aching", "acidic", "acrobatic", "active", + "actual", "adept", "admirable", "admired", "adolescent", "adorable", "adored", + "advanced", "adventurous", "affectionate", "afraid", "aged", "aggravating", + "aggressive", "agile", "agitated", "agonizing", "agreeable", "ajar", + "alarmed", "alarming", "alert", "alienated", "alive", "all", "altruistic", + "amazing", "ambitious", "ample", "amused", "amusing", "anchored", "ancient", + "angelic", "angry", "anguished", "animated", "annual", "another", "antique", + "anxious", "any", "apprehensive", "appropriate", "apt", "arctic", "arid", + "aromatic", "artistic", "ashamed", "assured", "astonishing", "athletic", + "attached", "attentive", "attractive", "austere", "authentic", "authorized", + "automatic", "avaricious", "average", "aware", "awesome", "awful", "awkward", + "babyish", "back", "bad", "baggy", "bare", "barren", "basic", "beautiful", + "belated", "beloved", "beneficial", "best", "better", "bewitched", "big", + "big-hearted", "biodegradable", "bite-sized", "bitter", "black", + "black-and-white", "bland", "blank", "blaring", "bleak", "blind", "blissful", + "blond", "blue", "blushing", "bogus", "boiling", "bold", "bony", "boring", + "bossy", "both", "bouncy", "bountiful", "bowed", "brave", "breakable", + "brief", "bright", "brilliant", "brisk", "broken", "bronze", "brown", + "bruised", "bubbly", "bulky", "bumpy", "buoyant", "burdensome", "burly", + "bustling", "busy", "buttery", "buzzing", "calculating", "calm", "candid", + "canine", "capital", "carefree", "careful", "careless", "caring", "cautious", + "cavernous", "celebrated", "charming", "cheap", "cheerful", "cheery", "chief", + "chilly", "chubby", "circular", "classic", "clean", "clear", "clear-cut", + "clever", "close", "closed", "cloudy", "clueless", "clumsy", "cluttered", + "coarse", "cold", "colorful", "colorless", "colossal", "comfortable", + "common", "compassionate", "competent", "complete", "complex", "complicated", + "composed", "concerned", "concrete", "confused", "conscious", "considerate", + "constant", "content", "conventional", "cooked", "cool", "cooperative", + "coordinated", "corny", "corrupt", "costly", "courageous", "courteous", + "crafty" +] + +var animals = [ + "aardvark", "african buffalo", "albatross", "alligator", "alpaca", "ant", + "anteater", "antelope", "ape", "armadillo", "baboon", "badger", "barracuda", + "bat", "bear", "beaver", "bee", "bison", "black panther", "blue jay", "boar", + "butterfly", "camel", "capybara", "carduelis", "caribou", "cassowary", "cat", + "caterpillar", "cattle", "chamois", "cheetah", "chicken", "chimpanzee", + "chinchilla", "chough", "clam", "cobra", "cockroach", "cod", "cormorant", + "coyote", "crab", "crane", "crocodile", "crow", "curlew", "deer", "dinosaur", + "dog", "dolphin", "domestic pig", "donkey", "dotterel", "dove", "dragonfly", + "duck", "dugong", "dunlin", "eagle", "echidna", "eel", "elephant seal", + "elephant", "elk", "emu", "falcon", "ferret", "finch", "fish", "flamingo", + "fly", "fox", "frog", "gaur", "gazelle", "gerbil", "giant panda", "giraffe", + "gnat", "goat", "goldfish", "goose", "gorilla", "goshawk", "grasshopper", + "grouse", "guanaco", "guinea fowl", "guinea pig", "gull", "hamster", "hare", + "hawk", "hedgehog", "heron", "herring", "hippopotamus", "hornet", "horse", + "human", "hummingbird", "hyena", "ibex", "ibis", "jackal", "jaguar", "jay", + "jellyfish", "kangaroo", "kingfisher", "koala", "komodo dragon", "kookabura", + "kouprey", "kudu", "lapwing", "lark", "lemur", "leopard", "lion", "llama", + "lobster", "locust", "loris", "louse", "lyrebird", "magpie", "mallard", + "manatee", "mandrill", "mantis", "marten", "meerkat", "mink", "mole", + "mongoose", "monkey", "moose", "mosquito", "mouse", "mule", "narwhal", "newt", + "nightingale", "octopus", "okapi", "opossum", "oryx", "ostrich", "otter", + "owl", "oyster", "parrot", "partridge", "peafowl", "pelican", "penguin", + "pheasant", "pigeon", "pinniped", "polar bear", "pony", "porcupine", + "porpoise", "prairie dog", "quail", "quelea", "quetzal", "rabbit", "raccoon", + "ram", "rat", "raven", "red deer", "red panda", "reindeer", "rhinoceros", + "rook", "salamander", "salmon", "sand dollar", "sandpiper", "sardine", + "scorpion", "sea lion", "sea urchin", "seahorse", "shark", "sheep", "shrew", + "skunk", "snail", "snake", "sparrow", "spider", "spoonbill", "squid", + "wallaby", "wildebeest" +] + +var keys = [] +for (animal in animals) { + for (adjective in adjectives) { + for (adverb in adverbs) { + keys.add(adverb + " " + adjective + " " + animal) + } + } +} + +var start = IO.clock + +var map = {} + +for (key in keys) { + map[key] = key.count +} + +var sum = 0 +for (key in keys) { + sum = sum + map[key] +} + +for (key in keys) { + map.remove(key) +} + +IO.print(sum) +IO.print("elapsed: ", IO.clock - start) diff --git a/script/benchmark.py b/script/benchmark.py old mode 100644 new mode 100755 index eb2c168f..bce5c005 --- a/script/benchmark.py +++ b/script/benchmark.py @@ -44,7 +44,9 @@ BENCHMARK("for", r"""499999500000""") BENCHMARK("method_call", r"""true false""") -BENCHMARK("maps", r"""5000050000""") +BENCHMARK("map_numeric", r"""500000500000""") + +BENCHMARK("map_string", r"""3645600""") LANGUAGES = [ ("wren", [os.path.join(WREN_DIR, 'wren')], ".wren"),