{"id":25565956,"url":"https://github.com/thadeu/binary-search-ruby-study","last_synced_at":"2026-03-15T05:30:18.981Z","repository":{"id":276900772,"uuid":"930677839","full_name":"thadeu/binary-search-ruby-study","owner":"thadeu","description":"An repository to share my study with binary search algorithm using pure Ruby","archived":false,"fork":false,"pushed_at":"2025-02-11T03:20:44.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-11T03:28:14.314Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/thadeu.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":"2025-02-11T02:56:17.000Z","updated_at":"2025-02-11T03:20:47.000Z","dependencies_parsed_at":"2025-02-11T03:39:33.426Z","dependency_job_id":null,"html_url":"https://github.com/thadeu/binary-search-ruby-study","commit_stats":null,"previous_names":["thadeu/binary-search-ruby-study"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Fbinary-search-ruby-study","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Fbinary-search-ruby-study/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Fbinary-search-ruby-study/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Fbinary-search-ruby-study/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thadeu","download_url":"https://codeload.github.com/thadeu/binary-search-ruby-study/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239922483,"owners_count":19718969,"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","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":[],"created_at":"2025-02-20T22:21:24.237Z","updated_at":"2026-03-15T05:30:18.932Z","avatar_url":"https://github.com/thadeu.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Study for Binary Search algorithm.\n\nI created a benchmark to compare the performance of the binary search and linear search algorithms in Ruby.\n\nThis is a simple implementation of the binary search algorithm in Ruby.\n\n```rb\nclass BinarySearch\n  def self.bsearch(arr, target_value)\n    low = 0\n    high = arr.size - 1\n\n    while low \u003c= high\n      mid = (low + high) / 2\n\n      if arr[mid] == target_value\n        return mid\n      elsif target_value \u003e arr[mid]\n        low = mid + 1\n      else\n        high = mid - 1\n      end\n    end\n\n    return 0\n  end\nend\n```\n\n```bash\nCalculating -------------------------------------\n LinearSearch.search          15.338k (± 4.2%) i/s   (65.20 μs/i) -     15.221k in   0.997098s\n LinearSearch.linear_search   24.463k (± 2.8%) i/s   (40.88 μs/i) -     24.320k in   0.995080s\n BinarySearch.search          614.120k (±34.2%) i/s    (1.63 μs/i) -    509.488k in   0.903576s\n BinarySearch.bsearch         823.586k (±29.0%) i/s    (1.21 μs/i) -    646.574k in   0.875338s\n [native] Array#bsearch       999.857k (± 1.0%) i/s    (1.00 μs/i) -    814.751k in   0.815340s\n\nComparison:\n [native] Array#bsearch:        999857.4 i/s\n BinarySearch.bsearch:          823585.7 i/s - same-ish: difference falls...\n BinarySearch.search:           614120.4 i/s - 1.63x  slower\n LinearSearch.linear_search:    24462.8 i/s - 40.87x  slower\n LinearSearch.search:           15338.0 i/s - 65.19x  slower\n```\n\nSo, after run my benchmark, I discover that Array#bsearch native method is so good and many fastest than my implementations.\n\n`BinarySearch.bsearch` have a little performance than other implementations, using recursive algorithm and mid, high navigation, improve performance to search value in the tree.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthadeu%2Fbinary-search-ruby-study","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthadeu%2Fbinary-search-ruby-study","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthadeu%2Fbinary-search-ruby-study/lists"}