{"id":1070,"date":"2010-05-17T17:14:09","date_gmt":"2010-05-17T16:14:09","guid":{"rendered":"http:\/\/soci.hu\/blog\/?p=1070"},"modified":"2010-05-17T17:15:48","modified_gmt":"2010-05-17T16:15:48","slug":"dynamic-sebesseg-ujra","status":"publish","type":"post","link":"https:\/\/soci.hu\/blog\/index.php\/2010\/05\/17\/dynamic-sebesseg-ujra\/","title":{"rendered":"Dynamic sebess\u00e9g \u00fajra"},"content":{"rendered":"<p>Hogy ne a <a href=\"http:\/\/soci.hu\/blog\/index.php\/2010\/05\/17\/miert-szeretem-a-dynamic-tipust-reflection-helyett\/\">leveg\u0151be besz\u00e9ljek<\/a>:<\/p>\n<p>using System;<br \/>\nusing System.Diagnostics;<br \/>\nusing System.Reflection;<\/p>\n<p>namespace DynamicTypeTest<br \/>\n{<br \/>\n    class Program<br \/>\n    {<br \/>\n        static void Main(string[] args)<br \/>\n        {<br \/>\n            object target = &#8220;alma&#8221;;<br \/>\n            object arg = &#8220;m&#8221;;<\/p>\n<p>            string a2 = (string)arg;<\/p>\n<p>            Stopwatch w = Stopwatch.StartNew();<\/p>\n<p>            const int callNumber = 1000 * 1000;<br \/>\n            for (int i = 0; i < callNumber; i++)\n            {\n                Type[] argTypes = new Type[] { typeof(string) };\n                MethodInfo mi = target.GetType().GetMethod(\"Contains\", argTypes);\n                object[] oa = new object[] { a2 };\n                bool b = (bool)mi.Invoke(target, oa);\n            }\n\n            w.Stop();\n            Console.WriteLine(\"Reflection h\u00edv\u00e1si id\u0151: {0}\", w.Elapsed);\n            double elapsedTickForReflection = w.ElapsedTicks;\n\n            w.Restart();\n\n            for (int i = 0; i < callNumber; i++)\n            {\n                bool b = ((dynamic)target).Contains(a2);\n            }\n\n            w.Stop();\n            Console.WriteLine(\"Dynamic h\u00edv\u00e1si id\u0151: {0}\", w.Elapsed);\n\n            Console.WriteLine(\"A dynamic {0}x gyorsabb volt.\", elapsedTickForReflection \/ w.ElapsedTicks);\n        }\n    }\n}\n[\/source]\n\n[source='C']\nReflection h\u00edv\u00e1si id\u0151: 00:00:02.5393161\nDynamic h\u00edv\u00e1si id\u0151: 00:00:00.2049100\nA dynamic 12.3923444658829x gyorsabb volt.\n[\/source]\n\nHa \u00fcgyesebbek vagyunk, \u00e9s kivessz\u00fck a ciklusb\u00f3l a reflection el\u0151k\u00e9sz\u00edt\u00e9s\u00e9t:\n\n[source='C#']\nusing System;\nusing System.Diagnostics;\nusing System.Reflection;\n\nnamespace DynamicTypeTest\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            object target = \"alma\";\n            object arg = \"m\";\n\n            string a2 = (string)arg;\n\n            Stopwatch w = Stopwatch.StartNew();\n\n            Type[] argTypes = new Type[] { typeof(string) };\n            MethodInfo mi = target.GetType().GetMethod(\"Contains\", argTypes);\n            object[] oa = new object[] { a2 };\n\n            const int callNumber = 1000 * 1000;\n            for (int i = 0; i < callNumber; i++)\n            {\n                bool b = (bool)mi.Invoke(target, oa);\n            }\n\n            w.Stop();\n            Console.WriteLine(\"Reflection h\u00edv\u00e1si id\u0151: {0}\", w.Elapsed);\n            double elapsedTickForReflection = w.ElapsedTicks;\n\n            w.Restart();\n\n            for (int i = 0; i < callNumber; i++)\n            {\n                bool b = ((dynamic)target).Contains(a2);\n            }\n\n            w.Stop();\n            Console.WriteLine(\"Dynamic h\u00edv\u00e1si id\u0151: {0}\", w.Elapsed);\n\n            Console.WriteLine(\"A dynamic {0}x gyorsabb volt.\", elapsedTickForReflection \/ w.ElapsedTicks);\n        }\n    }\n}\n[\/source]\n\n[source='C']\nReflection h\u00edv\u00e1si id\u0151: 00:00:01.2058747\nDynamic h\u00edv\u00e1si id\u0151: 00:00:00.2044023\nA dynamic 5.89951388765798x gyorsabb volt.\n[\/source]\n\nJ\u00f3 ez, szeretj\u00fck, pedig nem is COMolunk.\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hogy ne a leveg\u0151be besz\u00e9ljek: using System; using System.Diagnostics; using System.Reflection; namespace DynamicTypeTest { class Program { static void Main(string[] args) {&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,75,10,4],"tags":[],"class_list":["post-1070","post","type-post","status-publish","format-standard","hentry","category-net","category-net-4","category-c","category-szakmai-elet"],"_links":{"self":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1070"}],"version-history":[{"count":3,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1070\/revisions"}],"predecessor-version":[{"id":1073,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1070\/revisions\/1073"}],"wp:attachment":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}