{"id":17077787,"url":"https://github.com/torokmark/ruby-benchmark","last_synced_at":"2025-07-29T01:03:05.239Z","repository":{"id":148678965,"uuid":"200279368","full_name":"torokmark/ruby-benchmark","owner":"torokmark","description":"Benchmarked Ruby code snippets","archived":false,"fork":false,"pushed_at":"2019-08-09T16:20:26.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T12:17:51.640Z","etag":null,"topics":["benchmark","ruby"],"latest_commit_sha":null,"homepage":"https://torokmark.github.io/post/ruby-benchmark-control-flows/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/torokmark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-02T18:18:10.000Z","updated_at":"2024-07-25T08:11:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"40002369-ddb3-4fa3-8bb5-4bfb2a67a090","html_url":"https://github.com/torokmark/ruby-benchmark","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/torokmark/ruby-benchmark","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torokmark%2Fruby-benchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torokmark%2Fruby-benchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torokmark%2Fruby-benchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torokmark%2Fruby-benchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/torokmark","download_url":"https://codeload.github.com/torokmark/ruby-benchmark/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torokmark%2Fruby-benchmark/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267612616,"owners_count":24115494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","ruby"],"created_at":"2024-10-14T12:16:49.566Z","updated_at":"2025-07-29T01:03:05.182Z","avatar_url":"https://github.com/torokmark.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Goal\n\nThis repo is intended to be the place of benchmarked ruby codes.\n\n### Benchmark\n\nBenchmark is a Ruby module to measure the performance of a code or a sample. \n\n### Results\n\n---\n\n#### Object nil check :: nil vs == vs .nil?\n```\n                           user     system      total        real\nif nil else            0.289422   0.000045   0.289467 (  0.289472)\nunless nil             0.274994   0.000000   0.274994 (  0.275007)\n==                     0.314677   0.000000   0.314677 (  0.314693)\n.nil?                  0.323593   0.000000   0.323593 (  0.323600)\n```\n---\n\n#### Integer Increase check :: next vs += vs = +\n```\n                           user     system      total        real\n.next                  0.215632   0.000000   0.215632 (  0.215641)\n+=                     0.184815   0.000000   0.184815 (  0.184821)\n= +                    0.186315   0.000000   0.186315 (  0.186323)\n```\n---\n\n#### Loops :: break if vs while vs until vs do-while vs for vs times\n```\n                           user     system      total        real\nbreak if               0.298159   0.000000   0.298159 (  0.298164)\nwhile                  0.168136   0.000000   0.168136 (  0.168140)\nuntil                  0.170434   0.000000   0.170434 (  0.170440)\ndo-while               0.169096   0.000000   0.169096 (  0.169099)\nfor                    0.293484   0.000000   0.293484 (  0.293492)\ntimes                  0.275150   0.000000   0.275150 (  0.275156)\neach                   0.274378   0.000000   0.274378 (  0.274384)\n```\n---\n\n#### Statement Modifier check :: if ... vs ... if\n```\n                           user     system      total        real\nif ...                 0.185258   0.000019   0.185277 (  0.185281)\n... if                 0.187638   0.000000   0.187638 (  0.187642)\nunless ...             0.187996   0.000000   0.187996 (  0.188010)\n... unless             0.187703   0.000000   0.187703 (  0.187711)\n```\n---\n\n#### Array Create check :: new vs []\n```\n                           user     system      total        real\n[]                     0.249551   0.000013   0.249564 (  0.249571)\nnew                    0.492069   0.000000   0.492069 (  0.492206)\n```\n---\n\n#### Array Create with values\n```\n                           user     system      total        real\n[*..]                  0.158053   0.035978   0.194031 (  0.194037)\n(..).to_a              0.135544   0.015992   0.151536 (  0.151801)\nArray(..)              0.127350   0.023987   0.151337 (  0.173017)\nArray.new(n, \u0026:next)   0.316512   0.016014   0.332526 (  0.332534)\n```\n---\n\n#### Array Empty check :: == vs .empty?\n```\n                           user     system      total        real\n==                     1.327196   0.007977   1.335173 (  1.335311)\n.empty?                0.621629   0.000000   0.621629 (  0.621641)\n```\n---\n\n#### Array Push check :: push vs append vs \u003c\u003c\n```\n                           user     system      total        real\npush                   0.349599   0.000000   0.349599 (  0.349610)\nappend                 0.348777   0.000000   0.348777 (  0.348786)\n\u003c\u003c                     0.293359   0.000000   0.293359 (  0.293364)\n```\n---\n\n#### Array Concat check :: + vs concat\n```\n                           user     system      total        real\n+                      0.737956   0.000000   0.737956 (  0.738084)\nconcat                 0.934131   0.000000   0.934131 (  0.934153)\n```\n---\n\n#### Array First check :: first vs take vs slice\n```\n                           user     system      total        real\n[]                     0.341547   0.000000   0.341547 (  0.341553)\nfirst                  0.327909   0.000000   0.327909 (  0.328044)\ntake                   0.340037   0.000000   0.340037 (  0.340047)\nslice                  0.384472   0.000000   0.384472 (  0.384478)\n```\n---\n\n#### Array Find check :: find_index vs index\n```\n                           user     system      total        real\nfind_index             1.223887   0.000000   1.223887 (  1.224024)\nindex                  1.278570   0.000000   1.278570 (  1.278638)\n```\n---\n\n#### Array Size check :: length vs size\n```\n                           user     system      total        real\nsize                   0.158739   0.000000   0.158739 (  0.158745)\nlength                 0.160795   0.000000   0.160795 (  0.160801)\n```\n---\n\n#### Array Multiplication check :: * vs concat vs push\n```\n                           user     system      total        real\n*                      0.009856   0.007945   0.017801 (  0.017807)\nconcat                 0.317438   0.008017   0.325455 (  0.327402)\npush                   0.327907   0.016000   0.343907 (  0.345622)\nflattern               0.833131   0.026177   0.859308 (  0.859338)\n```\n---\n\n#### Array Branch Prediction check :: sorted vs unsorted\n```\n                           user     system      total        real\nsorted                 0.198496   0.000000   0.198496 (  0.198497)\nunsorted               0.220462   0.000000   0.220462 (  0.220470)\n```\n---\n\n#### Hash Create\n```\n                           user     system      total        real\n{}                     0.226806   0.003969   0.230775 (  0.230780)\nnew                    1.387572   0.000054   1.387626 (  1.387674)\n```\n---\n\n#### Hash Empty\n```\n                           user     system      total        real\n==                     0.348411   0.000000   0.348411 (  0.348482)\nkeys == []             6.861634   0.024025   6.885659 (  6.899134)\nlength                 0.202894   0.000000   0.202894 (  0.202896)\nempty?                 0.175827   0.000000   0.175827 (  0.175834)\nany?                   1.147780   0.000000   1.147780 (  1.147804)\n\u003c=                     0.318174   0.000000   0.318174 (  0.318186)\neql?{}                 0.300092   0.000000   0.300092 (  0.300097)\n{}.eql?                0.304485   0.000000   0.304485 (  0.304497)\n```\n---\n\n#### Hash Add\n```\n                           user     system      total        real\n[]                     0.368517   0.000000   0.368517 (  0.368526)\nstore                  0.375573   0.031975   0.407548 (  0.407558)\nmerge                  0.773256   0.016015   0.789271 (  0.789291)\n```\n---\n\n#### Hash Delete\n```\n                           user     system      total        real\ndelete                 1.779143   0.000000   1.779143 (  1.779179)\ndelete_if              1.953289   0.016003   1.969292 (  1.969318)\n```\n---\n\n#### Hash Delete All\n```\n                           user     system      total        real\n{}                     1.503435   0.000000   1.503435 (  1.503467)\nclear                  1.463241   0.000000   1.463241 (  1.463255)\ndelete_if              2.162543   0.000000   2.162543 (  2.162563)\nreject                 2.166870   0.000000   2.166870 (  2.166903)\n```\n---\n\n#### Hash Each\n```\n                           user     system      total        real\neach                   4.525632   0.000000   4.525632 (  4.525676)\neach_pair              4.319747   0.000000   4.319747 (  4.319790)\neach_key               4.255643   0.000000   4.255643 (  4.255699)\nkeys                   4.040172   0.000000   4.040172 (  4.040214)\n```\n---\n\n#### Hash Get\n```\n                           user     system      total        real\n[]                     0.240220   0.000000   0.240220 (  0.240223)\nfetch                  0.303289   0.000000   0.303289 (  0.303298)\ndig                    0.291008   0.000000   0.291008 (  0.291020)\n```\n---\n\n#### Hash Has Key\n```\n                           user     system      total        real\n[]                     0.349962   0.000000   0.349962 (  0.349969)\n.has_key?              0.447044   0.000000   0.447044 (  0.447055)\n.key?                  0.412049   0.000000   0.412049 (  0.412056)\n.include?              0.373655   0.000000   0.373655 (  0.373662)\n.member?               0.370867   0.000000   0.370867 (  0.370875)\n```\n---\n\n#### Hash Select Specific\n```\n                           user     system      total        real\nkeep_if                0.247874   0.000000   0.247874 (  0.247880)\nselect                 0.517125   0.000000   0.517125 (  0.517137)\ndelete_if              0.282292   0.000000   0.282292 (  0.282299)\nslice                  0.932576   0.000000   0.932576 (  0.932589)\n```\n---\n\n#### Hash Size\n```\n                           user     system      total        real\nsize                   0.164398   0.000000   0.164398 (  0.164403)\nlength                 0.162099   0.000000   0.162099 (  0.162101)\n```\n---\n\n#### String Create :: string lit vs new vs new + string lit\n```\n                           user     system      total        real\nstring literal         0.236834   0.000000   0.236834 (  0.236839)\nnew                    0.428730   0.000000   0.428730 (  0.428736)\nnew + string lit       0.967768   0.000000   0.967768 (  0.967788)\n```\n---\n\n#### String Concat :: + vs += vs \u003c\u003c vs concat vs prepend vs interpolation\n```\n                           user     system      total        real\n= +                    0.014046   0.000000   0.014046 (  0.014050)\n+=                     0.009382   0.000000   0.009382 (  0.009387)\n\u003c\u003c                     0.000779   0.000000   0.000779 (  0.000779)\nconcat                 0.000896   0.000000   0.000896 (  0.000896)\nprepend                0.007321   0.000000   0.007321 (  0.007321)\ninterpolation          0.056461   0.000000   0.056461 (  0.056467)\n```\n---\n\n#### String Concat Capacity :: with vs without cap\n```\n                           user     system      total        real\nwith capacity          0.090962   0.000000   0.090962 (  0.090967)\nwithout capacity       0.090428   0.000000   0.090428 (  0.090433)\n```\n---\n\n#### String End With :: regex vs end_with\n```\n                           user     system      total        real\nregex =~               1.111580   0.000000   1.111580 (  1.111597)\nregex match            0.801556   0.000000   0.801556 (  0.801572)\nend_with               0.446056   0.000000   0.446056 (  0.446064)\n```\n---\n\n#### String Include :: regex vs index vs include\n```\n                           user     system      total        real\nregex =~ with ends     1.136864   0.000000   1.136864 (  1.136877)\nregex =~               0.943140   0.000000   0.943140 (  0.943151)\nregex match            0.619866   0.000000   0.619866 (  0.619875)\ninclude                0.578103   0.000000   0.578103 (  0.578112)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorokmark%2Fruby-benchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftorokmark%2Fruby-benchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorokmark%2Fruby-benchmark/lists"}