node-methodmissing benchmark
install dependencies
% npm install
run
% coffee bench.coffee
% coffee bench.coffee > result.txt
みどころ
- methodmissingを適応したオブジェクトは、通常の関数呼び出しが遅くなる
- methodmissingな関数よりも遅くなる
*~ | |
*#* | |
.DS_Store | |
node_modules | |
tmp |
method_missing = require 'methodmissing' | |
bench = (title, times, func)-> | |
## console.log "== #{title} #{times} times : start" | |
start_at = new Date() | |
for [0...times] | |
func() | |
elapsed_time = new Date() - start_at | |
console.log "== #{title} #{times} times : end - #{elapsed_time}(usec)" | |
class Foo | |
bar: (arg1, arg2, arg3)-> | |
## console.log "bar()" | |
foo = new Foo() | |
foo.baz = "bazbaz" | |
bench "function call", 10000000, foo.bar | |
bench "property read", 10000000, -> | |
foo.baz | |
foo = method_missing foo, (func_name, args)-> | |
## console.log "#{func_name}(#{args})" | |
bench "method-missing", 10000000, foo.this_method_is_not_implemented | |
bench "property-missing", 10000000, -> | |
foo.this_property_is_not_implemented | |
bench "function call without methodmissing", 10000000, foo.bar | |
bench "property read without methodmissing", 10000000, -> | |
foo.baz |
{ | |
"name": "node-methodmissing-bench", | |
"version": "0.0.0", | |
"description": "node-methodmissing's benchmark", | |
"main": "bench.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Sho Hashimoto <hashimoto@shokai.org>", | |
"license": "MIT", | |
"dependencies": { | |
"methodmissing": "~0.0.1", | |
"coffee-script": "~1.6.3" | |
} | |
} |
== function call 10000000 times : end - 24(usec) | |
== property read 10000000 times : end - 71(usec) | |
== method-missing 10000000 times : end - 1699(usec) | |
== property-missing 10000000 times : end - 3671(usec) | |
== function call without methodmissing 10000000 times : end - 2631(usec) | |
== property read without methodmissing 10000000 times : end - 3809(usec) |