Giter Club home page Giter Club logo

luabench's Introduction

luabench

luabench is a benchmarking tool designed for unit benchmarking of Lua modules in Tarantool. It draws inspiration from Go's testing/benchmark, bringing similar functionality to the Lua ecosystem. With luabench, you can easily measure and analyze the performance of your Lua code.

Features and Capabilities

  • Selective Benchmarking: Targets files with '_bench.lua' suffix in the working directory.
  • Customizable Duration and Iterations: Specify the benchmark duration (-d) in seconds (e.g., -d 10s) or iterations (e.g., -d 1000x).
  • Sequential Execution: Each benchmark function is executed in a separate fiber sequentially, not concurrently.
  • Performance Metrics: Reports the average time per operation and average operations per second, along with total allocated memory for each benchmark test.
  • Output Format: Benchmark results are output to stdout in the same format as Go's testing/benchmark.
  • Skipping and Failing Benchmarks: Users can skip a benchmark by calling b:skip("<skip-reason>") or fail a benchmark using b:fail("<fail-reason>").

Status

Early proof-of-concept

Latest release: 0.1.0

Installation

Via Tarantool Rocks:

tt rocks --server https://moonlibs.org install luabench 0.1.0

Manual Download: Download luabench.lua from github.com/moonlibs/luabench and execute it.

Usage

Create a file named 001_example_bench.lua in your working project and write a benchmark test like the following:

-- Example benchmark test
local M = {}

---@param b luabench.B
function M.bench_sum(b)
    local sum = 0
    for i = 1, b.N do
        sum = sum + i
    end
end

return M

Define benchmark functions with the bench_ prefix. These functions should accept a luabench.B type argument and respect the b.N field for loop iterations. Benchmarks can be skipped or failed using b:skip("<skip-reason>") or b:fail("<fail-reason>"), respectively.

To parameterize benchmarks, use sub-benchmarks as follows:

-- Sub-benchmark example
local M = {}

function M.bench_insert(b)
    b:run("table-100", function(sb)
        for i = 1, sb.N do
            t[i%100+1] = true
        end
    end)
    b:run("table-1000", function(sb)
        for i = 1, sb.N do
            t[i%1000+1] = true
        end
    end)
end

return M

Command Line Usage

Usage: luabench [-v] [-d <d>] [-h] [<path>]

Runs lua code benchmarks

Arguments:
   path                  Run benchmark from specified paths (default: .)

Options:
   -v, --verbose         Increase verbosity
   -d <d>                Test duration limit
   -h, --help            Show this help message and exit.

Example Output

.rocks/bin/luabench -d 100x examples/001_bench.lua
Tarantool version: 2.11.1-0-g96877bd
Tarantool build: Darwin-arm64-RelWithDebInfo
CPU: Apple M1 @ 8
JIT: Disabled
Duration: 100 iters

--- SKIP:  001_bench::bench_insert:local-table

--- BENCH: 001_bench::bench_insert:rewrite-1000
     100                30.00 ns/op       33333333 op/s       38 B/op   +3.72KB

--- BENCH: 001_bench::bench_insert:temporary-space
     100               410.0 ns/op         2439024 op/s       91 B/op   +8.96KB

--- SKIP:  001_bench::bench_sum

Dependencies

No external dependencies required.

Contributing

Contributions are welcome! Feel free to suggest pull requests at github.com/moonlibs/luabench.

License

luabench is MIT licensed. See LICENSE for more details.

Contact

For support, feedback, or contributions, please file tickets at github.com/moonlibs/luabench.

luabench's People

Contributors

ochaton avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.