Skip to content

Commit

Permalink
First commit after rework
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed May 19, 2022
1 parent a279f90 commit 72cf392
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 171 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
@@ -0,0 +1,32 @@
name: test

on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:

jobs:
raku:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
raku-version:
- 'latest'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: Raku/setup-raku@v1
with:
raku-version: ${{ matrix.raku-version }}
- name: Install Dependencies
run: zef install --/test --test-depends --deps-only .
- name: Install App::Prove6
run: zef install --/test App::Prove6
- name: Run Tests
run: prove6 -I. t
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
lib/.precomp
.precomp/
/Benchy-*
4 changes: 4 additions & 0 deletions Changes
@@ -0,0 +1,4 @@
Revision history for Benchy

{{$NEXT}}
- First version in the zef ecosystem
45 changes: 29 additions & 16 deletions META6.json
@@ -1,18 +1,31 @@
{
"perl" : "6.c",
"name" : "Benchy",
"license" : "Artistic-2.0",
"version" : "1.001001",
"description" : "Benchmark some code",
"tags" : [ "benchmark", "dev" ],
"depends" : [ ],
"test-depends" : [
"Testo",
"Test::META"
],
"provides" : {
"Benchy" : "lib/Benchy.pm6"
},
"authors" : ["Zoffix Znet"],
"support" : {"source" : "https://github.com/raku-community-modules/Benchy.git"}
"auth": "zef:raku-community-modules",
"authors": [
"Zoffix Znet"
],
"build-depends": [
],
"depends": [
],
"description": "Benchmark some code",
"license": "Artistic-2.0",
"name": "Benchy",
"perl": "6.c",
"provides": {
"Benchy": "lib/Benchy.rakumod"
},
"resources": [
],
"source-url": "https://github.com/raku-community-modules/Benchy.git",
"support": {
"source": "https://github.com/raku-community-modules/Benchy.git"
},
"tags": [
"benchmark",
"dev"
],
"test-depends": [
"Testo"
],
"version": "1.1"
}
134 changes: 61 additions & 73 deletions README.md
@@ -1,106 +1,94 @@
[![Build Status](https://travis-ci.org/zoffixznet/perl6-Benchy.svg)](https://travis-ci.org/zoffixznet/perl6-Benchy)
[![Actions Status](https://github.com/raku-community-modules/Benchy/actions/workflows/test.yml/badge.svg)](https://github.com/raku-community-modules/Benchy/actions)

# NAME
NAME
====

Benchy - Benchmark some code

# SYNOPSIS
SYNOPSIS
========

```raku
use Benchy;
b 20_000, # number of times to loop
{ some-setup; my-old-code }, # your old version
{ some-setup; my-new-code }, # your new version
{ some-setup } # optional "bare" loop to eliminate setup code's time

# SAMPLE OUTPUT:
# Bare: 0.0606532677866851s
# Old: 2.170558s
# New: 0.185170s
# NEW version is 11.72x faster
use Benchy;

b 20_000, # number of times to loop
{ some-setup; my-old-code }, # your old version
{ some-setup; my-new-code }, # your new version
{ some-setup } # optional "bare" loop to eliminate setup code's time

# SAMPLE OUTPUT:
# Bare: 0.0606532677866851s
# Old: 2.170558s
# New: 0.185170s
# NEW version is 11.72x faster
```

# DESCRIPTION
DESCRIPTION
===========

Takes 2 `Callable`s and measures which one is faster. Optionally takes a 3rd
`Callable` that will be run the same number of times as other two callables,
and the time it took to run will be subtracted from the other results.
Takes 2 `Callable`s and measures which one is faster. Optionally takes a 3rd `Callable` that will be run the same number of times as other two callables, and the time it took to run will be subtracted from the other results.

# EXPORTED PRAGMAS
EXPORTED PRAGMAS
================

## `MONKEY`
MONKEY
------

The `use` of this module enables `MONKEY` pragma, so you can augment, use NQP,
EVAL, etc, without needing to specify those pragmas.
The `use` of this module enables `MONKEY` pragma, so you can augment, use NQP, EVAL, etc, without needing to specify those pragmas.

# EXPORTED SUBROUTINES
EXPORTED SUBROUTINES
====================

## `b`
b(int $n, &old, &new, &bare = { $ = $ }, :$silent)
--------------------------------------------------

Defined as:
Benches the codes and prints the results. Will print in colour, if [`Terminal::ANSIColor`](https://modules.raku.org/repo/Terminal::ANSIColor) is installed.

```raku
sub b (int $n, &old, &new, &bare = { $ = $ }, :$silent)
```
### $n

Benches the codes and prints the results. Will print in colour, if
[`Terminal::ANSIColor`](https://modules.raku.org/repo/Terminal::ANSIColor)
is installed.
How many times to loop.

**Args:**
Note that the exact number to loop will always be evened out, as the bench splits the work into two chunks that are measured at different times, so the total time is `2 × floor ½ × $n`.

- `$n` how many times to loop[^1]
- `&old` your "old" code; assumption is you have "old" code and you're trying
to write some "new" code to replace it
- `&new` your "new" code
- `&bare` optional (defaults to `{ $ = $ }`). When specified, this `Callable`
will be run same number of times as other code and the time it took to
run will be subtracted from the `&new` and `&old` times. Use this to
run some "setup" code. That is code that's used in `&new` and `&old` but
should not be part of the benched times
- `:$silent` if set to a truthy value, the routine will not print anything to
the screen
### &old

[1] Note that the exact number to loop will always be evened out,
as the bench splits the work into two chunks that are measured at different
times, so the total time is `2 × floor ½ × $n`
Your "old" code; assumption is you have "old" code and you're trying to write some "new" code to replace it.

**Return value:**
### &new

Returns a hash with three keys—`bare`, `new`, and `old`—whose values are
[`Duration`](https://docs.raku.org/type/Duration) objects representing the
time it took the corresponding `Callable`s to run. **NOTE:** the `new` and
`old` already have the duration of `bare` subtracted from them.
Your "new" code.

```raku
{
:bare(Duration.new(<32741983139/488599474770>)),
:new(Duration.new(<167/956>)),
:old(Duration.new(<1280561957330937733/590077351150947660>))
}
```
### &bare

Optional (defaults to `{ $ = $ }`). When specified, this `Callable` will be run same number of times as other code and the time it took to run will be subtracted from the `&new` and `&old` times. Use this to run some "setup" code. That is code that's used in `&new` and `&old` but should not be part of the benched times.

----
### :$silent

#### REPOSITORY
If set to a truthy value, the routine will not print anything.

Fork this module on GitHub:
https://github.com/raku-community-modules/Benchy
### returns

Returns a hash with three keys - `bare`, `new`, and `old` — whose values are `Duration` objects representing the time it took the corresponding `Callable`s to run. **NOTE:** the `new` and `old` already have the duration of `bare` subtracted from them.

```raku
{
:bare(Duration.new(<32741983139/488599474770>)),
:new(Duration.new(<167/956>)),
:old(Duration.new(<1280561957330937733/590077351150947660>))
}
```

#### BUGS
AUTHOR
======

To report bugs or request features, please use
https://github.com/raku-community-modules/Benchy/issues
Zoffix Znet

#### AUTHOR
COPYRIGHT AND LICENSE
=====================

Zoffix Znet (http://perl6.party/)
Copyright 2017 Zoffix Znet

#### LICENSE
Copyright 2018 - 2022 Raku Community

You can use and distribute this module under the terms of the
The Artistic License 2.0. See the `LICENSE` file included in this
distribution for complete details.
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

The `META6.json` file of this distribution may be distributed and modified
without restrictions or attribution.
13 changes: 13 additions & 0 deletions dist.ini
@@ -0,0 +1,13 @@
name = Benchy

[ReadmeFromPod]
; enabled = false
filename = lib/Benchy.rakumod

[UploadToZef]

[PruneFiles]
; match = ^ 'xt/'

[Badges]
provider = github-actions/test.yml
3 changes: 2 additions & 1 deletion examples/benchy.p6 → examples/benchy.raku
@@ -1,4 +1,3 @@
use lib <lib>;
use Benchy;

augment class IO::Spec::Win32 {
Expand All @@ -24,3 +23,5 @@ augment class IO::Spec::Win32 {
}

dd b 20, { sleep .1 }, { sleep .01 }, { sleep .001 }

# vim: expandtab shiftwidth=4
70 changes: 0 additions & 70 deletions lib/Benchy.pm6

This file was deleted.

0 comments on commit 72cf392

Please sign in to comment.