{"action":"created","issue":{"url":"https://api.github.com/repos/cpgf/cpgf/issues/61","labels_url":"https://api.github.com/repos/cpgf/cpgf/issues/61/labels{/name}","comments_url":"https://api.github.com/repos/cpgf/cpgf/issues/61/comments","events_url":"https://api.github.com/repos/cpgf/cpgf/issues/61/events","html_url":"https://github.com/cpgf/cpgf/issues/61","id":72099280,"number":61,"title":"A question regarding script binding performance","user":{"login":"Neovet","id":3635364,"avatar_url":"https://avatars.githubusercontent.com/u/3635364?v=3","gravatar_id":"","url":"https://api.github.com/users/Neovet","html_url":"https://github.com/Neovet","followers_url":"https://api.github.com/users/Neovet/followers","following_url":"https://api.github.com/users/Neovet/following{/other_user}","gists_url":"https://api.github.com/users/Neovet/gists{/gist_id}","starred_url":"https://api.github.com/users/Neovet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Neovet/subscriptions","organizations_url":"https://api.github.com/users/Neovet/orgs","repos_url":"https://api.github.com/users/Neovet/repos","events_url":"https://api.github.com/users/Neovet/events{/privacy}","received_events_url":"https://api.github.com/users/Neovet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-04-30T08:29:19Z","updated_at":"2015-05-04T10:18:39Z","closed_at":null,"body":"Hi,\r\n\r\nI've used luabind for script binding and then found cpgf and it seems so great, because I always planned to add reflection to my game engine.\r\n\r\nBut there is a little question regarding the performance.\r\n\r\nFirst, I made a benchmark to test the FindMetaMethod+Invoke scenario on i5-3570K for this class:\r\n```c++\r\nclass Test\r\n{\r\npublic:\r\n  int func(int a, int b)\r\n  {\r\n    return a + b;\r\n  }\r\n};\r\n```\r\n\r\n1) luabind\r\n```c++\r\nluabind::module(state)\r\n[\r\n  luabind::class_<Test>(\"Test\")\r\n    .def(constructor<>())\r\n    .def(\"func\", &Test::func)\r\n];\r\n```\r\n\r\n```lua\r\nlocal obj = Test()\r\nfor i = 1, 10000000 do\r\n    obj:func(1, 2)\r\nend\r\n```\r\n\r\nThis code took 1580ms.\r\n\r\n2) cpgf\r\n```c++\r\ncpgf::GDefineMetaClass<Test>\r\n  ::define(\"Test\")\r\n  ._method(\"func\", &CpgfTest::func);\r\n\r\nTest obj;\r\ncpgf::GMetaClass* t = cpgf::findMetaClass(\"Test\");\r\nfor (int i = 0; i < 10000000; ++i)\r\n{\r\n    cpgf::GMetaMethod* m = t->getMethod(\"func\");\r\n    cpgf::fromVariant<int>(m->invoke(&obj, 1, 2));\r\n}\r\n```\r\n\r\nThis code took 1135ms, so it's even faster than luabind and I'm happy.\r\n\r\n3) cpgf+lua\r\n\r\nModified samples/scriptbind/luabind/constructor.cpp sample - added similar TestObject::func method and bencmarked the last line from next code:\r\n```c++\r\nTestLuaContext context;\r\nGScopedInterface<IMetaClass> metaClass(context.getService()->findClassByName(\"testscript::TestObject\"));\r\ncontext.getBinding()->bindClass(\"TestObject\", metaClass.get());\r\ncontext.doString(\"a = TestObject()\\nfor i = 1, 1000000 do a.func(1, 2) end\\n\");\r\n```\r\n\r\nThis code took 61332ms, 38 times slower than luabind. I hope I mistaken somewhere.\r\nPlease help, because I would like very much to use your excellent library"},"comment":{"url":"https://api.github.com/repos/cpgf/cpgf/issues/comments/98669747","html_url":"https://github.com/cpgf/cpgf/issues/61#issuecomment-98669747","issue_url":"https://api.github.com/repos/cpgf/cpgf/issues/61","id":98669747,"user":{"login":"bagobor","id":708235,"avatar_url":"https://avatars.githubusercontent.com/u/708235?v=3","gravatar_id":"","url":"https://api.github.com/users/bagobor","html_url":"https://github.com/bagobor","followers_url":"https://api.github.com/users/bagobor/followers","following_url":"https://api.github.com/users/bagobor/following{/other_user}","gists_url":"https://api.github.com/users/bagobor/gists{/gist_id}","starred_url":"https://api.github.com/users/bagobor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bagobor/subscriptions","organizations_url":"https://api.github.com/users/bagobor/orgs","repos_url":"https://api.github.com/users/bagobor/repos","events_url":"https://api.github.com/users/bagobor/events{/privacy}","received_events_url":"https://api.github.com/users/bagobor/received_events","type":"User","site_admin":false},"created_at":"2015-05-04T10:18:39Z","updated_at":"2015-05-04T10:18:39Z","body":"@wqking Thanks for correcting me.\r\n\r\n@Neovet сорри не обратил внимание на ник автора статьи. А так да - мир программерский тесен. ))) You may also find useful https://github.com/decimad/luabind-deboostified project. I used it in several projects and it served well. I hope you'll find time to add it to your article.\r\n\r\n\r\n"}}