Skip to content

Instantly share code, notes, and snippets.

@shokai
Last active December 29, 2015 10:18
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 shokai/7655669 to your computer and use it in GitHub Desktop.
Save shokai/7655669 to your computer and use it in GitHub Desktop.
node-methodmissing benchmark https://github.com/geta6/node-methodmissing
*~
*#*
.DS_Store
node_modules
tmp

node-methodmissing benchmark

install dependencies

% npm install

run

% coffee bench.coffee
% coffee bench.coffee > result.txt

みどころ

  • methodmissingを適応したオブジェクトは、通常の関数呼び出しが遅くなる
    • methodmissingな関数よりも遅くなる
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment