{"id":105,"date":"2008-12-02T17:59:39","date_gmt":"2008-12-02T21:59:39","guid":{"rendered":"http:\/\/hoolihan.net\/blog-tim\/?p=105"},"modified":"2008-12-02T18:00:16","modified_gmt":"2008-12-02T22:00:16","slug":"105","status":"publish","type":"post","link":"http:\/\/hoolihan.net\/blog-tim\/2008\/12\/02\/105\/","title":{"rendered":"Benchmarking Recursion Using Factorial Function"},"content":{"rendered":"<p>def fact(n)<br \/>\n\u00a0 (1..n).to_a.inject(1){|f,n| f*n}<br \/>\nend<\/p>\n<p>def recursive_fact(n)<br \/>\n\u00a0 return n==1 ? n : n * recursive_fact(n-1)<br \/>\nend<\/p>\n<p>require &#8216;benchmark&#8217;<\/p>\n<p>Benchmark.bm do |b|<br \/>\n\u00a0 b.report(&#8220;inject&#8221;){1000.times{fact(100)}}<br \/>\n\u00a0 b.report(&#8220;recursive&#8221;){1000.times{recursive_fact(100)}}<br \/>\nend<\/p>\n","protected":false},"excerpt":{"rendered":"<p>def fact(n) \u00a0 (1..n).to_a.inject(1){|f,n| f*n} end def recursive_fact(n) \u00a0 return n==1 ? n : n * recursive_fact(n-1) end require &#8216;benchmark&#8217; Benchmark.bm do |b| \u00a0 b.report(&#8220;inject&#8221;){1000.times{fact(100)}} \u00a0 b.report(&#8220;recursive&#8221;){1000.times{recursive_fact(100)}} end<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,16],"tags":[],"class_list":["post-105","post","type-post","status-publish","format-standard","hentry","category-programming","category-ruby"],"_links":{"self":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/comments?post=105"}],"version-history":[{"count":0,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"wp:attachment":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/tags?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}