Coder Social home page Coder Social logo

benchy's Introduction

Benchy

nimble install benchy

Github Actions

API reference

This library has no dependencies other than the Nim standard library.

About

Simple benchmarking to time your code. Just put your code in a timeIt block. Also put result of your computation into keep() so that compiler does not optimize it out. Don't forgot to run with -d:release or better yet -d:danger.

timeIt "sleep 1ms":
  sleep(1)

timeIt "sleep 200ms":
  sleep(200)

timeIt "sleep random":
  sleep(rand(0 .. 150))

timeIt "number counter":
  var s = 0
  for i in 0 .. 1_000_000:
    s += s
  keep(s)

timeIt "string append":
  var s = "?"
  for i in 0 .. 26:
    s.add(s)
  keep(s)

It will run the timeIt block at least 10 times but possibly more to figure out the standard deviation. It will keep running it until things look like they stabilized. It will stop after 60s though.

name ............................... min time      avg time    std dv   runs
sleep 1ms .......................... 1.016 ms      1.993 ms    ±0.032  x1000
sleep 200ms ...................... 200.403 ms    200.463 ms    ±0.022    x25
sleep random ....................... 5.959 ms     75.490 ms   ±44.856    x67
number counter ..................... 2.680 ms      2.747 ms    ±0.052  x1000
string append ..................... 36.322 ms     37.796 ms    ±1.771   x127

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.