{"id":15343699,"url":"https://github.com/spacewander/luabenchmark","last_synced_at":"2025-04-15T03:21:28.279Z","repository":{"id":71091888,"uuid":"53018132","full_name":"spacewander/luabenchmark","owner":"spacewander","description":"A tiny library for benchmark. ","archived":false,"fork":false,"pushed_at":"2017-02-12T10:26:27.000Z","size":25,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T15:05:06.579Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","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/spacewander.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":"2016-03-03T03:39:25.000Z","updated_at":"2025-02-03T23:11:31.000Z","dependencies_parsed_at":"2023-03-11T09:53:43.131Z","dependency_job_id":null,"html_url":"https://github.com/spacewander/luabenchmark","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":"0.16666666666666663","last_synced_commit":"58324088c9971af4501279160f30f9ce22d79f5d"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacewander%2Fluabenchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacewander%2Fluabenchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacewander%2Fluabenchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacewander%2Fluabenchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spacewander","download_url":"https://codeload.github.com/spacewander/luabenchmark/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997451,"owners_count":21195879,"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":"2024-10-01T10:48:59.106Z","updated_at":"2025-04-15T03:21:28.235Z","avatar_url":"https://github.com/spacewander.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# luabenchmark\n\n[![Build Status](https://api.travis-ci.org/spacewander/luabenchmark.svg?branch=master)](http://travis-ci.org/spacewander/luabenchmark)\nA tiny library for benchmark.\n\n## doc\n\nSee \u003chttp://spacewander.github.io/luabenchmark/index.html\u003e\n\n## lua performance tips\n\nFrom \u003chttp://www.lua.org/gems/sample.pdf\u003e\n\n```\nlocal bm = require './benchmark'\nlocal reporter = bm.bm(6)\n```\n\n### use locals\n\n```\nreporter:report(function()\n    for i = 1, 1e6 do\n        local x = math.sin(i)\n    end\nend, 'slow')\n\nreporter:report(function()\n    local sin = math.sin\n    for i = 1, 1e6 do\n        local x = sin(i)\n    end\nend, 'fast')\n\n--slow   system: 0.140    user: 0.000 total: 0.140    real: 0.146\n--fast   system: 0.110    user: 0.000 total: 0.110    real: 0.109\n```\n\n### pre-create table space\n\n```\nreporter:report(function()\n    for i = 1, 1e6 do\n        local a = {}\n        a[1] = 1; a[2] = 2; a[3] = 3\n    end\nend, 'slow')\n\nreporter:report(function()\n    for i = 1, 1e6 do\n        local a = {nil, nil, nil}\n        a[1] = 1; a[2] = 2; a[3] = 3\n    end\nend, 'fast')\n\nslow   system: 0.810    user: 0.000 total: 0.810    real: 0.813\nfast   system: 0.350    user: 0.000 total: 0.350    real: 0.354\n```\n\n### use table.concat to concat strings in a loop\n\n```\nreporter:report(function()\n    local s = ''\n    for i = 1, 1e5 do\n        s = s .. 'aaa'\n    end\nend, 'slow')\n\nreporter:report(function()\n    local t = {}\n    for i = 1, 1e5 do\n        t[#t + 1] = 'aaa'\n    end\n    s = table.concat(t, '')\nend, 'fast')\n\nslow   system: 5.120    user: 2.860 total: 7.980    real: 7.998\nfast   system: 0.030    user: 0.000 total: 0.030    real: 0.030\n```\n\n### reduce, reuse, recycle\n\n```\nreporter:report(function()\n    local t = {}\n    local time = os.time\n    for i = 1, 1e5 do\n        t[i] = time({year = i, month = 6, day = 14})\n    end\nend, 'slow')\n\nreporter:report(function()\n    local t = {}\n    local time = os.time\n    local aux = {year = nil, month = 6, day = 14}\n    for i = 1, 1e5 do\n        aux.year = i\n        t[i] = time(aux)\n    end\nend, 'fast')\n\nslow   system: 0.270    user: 0.100 total: 0.370    real: 0.369\nfast   system: 0.200    user: 0.110 total: 0.310    real: 0.315\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacewander%2Fluabenchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspacewander%2Fluabenchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacewander%2Fluabenchmark/lists"}