{"id":16305219,"url":"https://github.com/moznion/lua-benchmarker","last_synced_at":"2025-04-11T13:50:25.149Z","repository":{"id":145078037,"uuid":"151110868","full_name":"moznion/lua-benchmarker","owner":"moznion","description":"A micro benchmarker for lua","archived":false,"fork":false,"pushed_at":"2018-10-16T16:22:06.000Z","size":21,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-24T05:11:48.558Z","etag":null,"topics":["benchmark","lua"],"latest_commit_sha":null,"homepage":"https://luarocks.org/modules/moznion/benchmarker","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moznion.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":"2018-10-01T15:23:17.000Z","updated_at":"2021-06-27T17:04:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"a258aaba-dccb-4c49-8af8-bda05fdedd6c","html_url":"https://github.com/moznion/lua-benchmarker","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"b564de7c6d23bdac9df7e1301e2e1c12dd5a753f"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Flua-benchmarker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Flua-benchmarker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Flua-benchmarker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Flua-benchmarker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moznion","download_url":"https://codeload.github.com/moznion/lua-benchmarker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239065734,"owners_count":19575774,"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":["benchmark","lua"],"created_at":"2024-10-10T21:06:03.558Z","updated_at":"2025-02-15T23:15:52.997Z","avatar_url":"https://github.com/moznion.png","language":"Lua","readme":"lua-benchmarker\n==\n\nA micro benchmarker for lua code.\n\nSynopsis\n--\n\n```lua\nlocal benchmarker = require 'benchmarker'\n\nbenchmarker.new({\n    [\"insert append\"] = function ()\n        local arr = {}\n        for i=1,1000 do\n            table.insert(arr, i)\n        end\n    end,\n    [\"index append\"] = function ()\n        local arr = {}\n        for i=1,1000 do\n            arr[i] = i\n        end\n    end,\n}):warmup(10):run_within_time(1):timethese():cmpthese()\n```\n\nthen it shows:\n\n```\nstarting warming up: 10\n\nScore:\n\nindex append:  1 wallclock secs ( 1.05 usr +  0.00 sys =  1.05 CPU) @ 51124.51/s (n=53695)\ninsert append:  1 wallclock secs ( 1.06 usr +  0.00 sys =  1.06 CPU) @ 9185.70/s (n=9760)\n\nComparison chart:\n\n                    Rate  index append  insert append\n   index append  51125/s            --           457%\n  insert append   9186/s          -82%             --\n```\n\nPlease refer also to the [example](./example).\n\nMethods\n--\n\n### `benchmarker` package\n\n#### `.new({functions})`\n\nA constructor. This method instantiates a benchmarker instance. This method receives a table of target functions.\n\ne.g.\n\n```lua\nbenchmarker.new({\n    [\"procedure 1\"] = function ()\n        -- do something\n    end,\n    [\"procedure 2\"] = function ()\n        -- do something\n    end,\n    ...\n})\n```\n\n#### `:warmup(ntimes)`\n\nThis method executes target functions `n` times. This warming up phase doesn't affect the result.\n\nThis method returns the self.\n\n#### `:timeit(ntimes, func)`\n\nThis method executes a chunk of given function and sees how long it goes.\n\nThis method returns `result` instance that contains the score.\n\n#### `:countit(timelimit, func)`\n\nThis method shows how many times a chunk of the function runs in a given time limit.\n\nThis method returns `result` and `err`. `result` contains the score.\n\n#### `:run(ntimes)`\n\nThis method executes `timeit()` for each function that is given by constructor.\n\nThe return value of this method is `result` instance that contains scores for each function.\n\n#### `:run_within_time(timelimit)`\n\nThis method executes `countit()` for each function that is given by constructor.\n\nThis method returns `result` and `err`. `result` instance that contains scores for each function.\n\n### `result` package\n\n#### `:timethese()`\n\nThis method prints score with execution time.\n\n#### `:cmpthese()`\n\nThis method prints score as a comparison chart.\n\nInstallation\n--\n\nThis package is provided by luarocks:\n\n```\n$ luarocks install benchmarker\n```\n\nCopyright\n--\n\nThis library was made with reference to the following:\n\n- [https://metacpan.org/source/XSAWYERX/perl-5.28.0/lib/Benchmark.pm](https://metacpan.org/source/XSAWYERX/perl-5.28.0/lib/Benchmark.pm)\n- [https://github.com/tokuhirom/nanobench](https://github.com/tokuhirom/nanobench)\n\nLicense\n--\n\n```\nThis software is Copyright (c) 2018 by moznion \u003cmoznion@gmail.com\u003e.\n\nThis is free software, licensed under:\n\n  The Artistic License 1.0\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Flua-benchmarker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoznion%2Flua-benchmarker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Flua-benchmarker/lists"}