From f47c3f0280bedfb8ca621bf68f2e1e90e82993e8 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Sat, 1 Aug 2020 10:00:18 +0200 Subject: [PATCH] use nix --- .gitignore | 2 + default.nix | 35 ++ lish-benchmark.html | 647 +++++++++++++++++++++++++++++++++++ nixpkgs.nix | 1 + release.nix | 4 + shell.nix | 1 + src/Lish/InternalCommands.hs | 4 +- tutorial.md | 98 ++++++ 8 files changed, 790 insertions(+), 2 deletions(-) create mode 100644 default.nix create mode 100644 lish-benchmark.html create mode 100644 nixpkgs.nix create mode 100644 release.nix create mode 100644 shell.nix create mode 100644 tutorial.md diff --git a/.gitignore b/.gitignore index 735a38e..28e58d8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .lish-history *.tix stack.yaml.lock +dist-newstyle/ +result diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..9431e26 --- /dev/null +++ b/default.nix @@ -0,0 +1,35 @@ +{ nixpkgs ? import ./nixpkgs.nix +, compiler ? "default" +, doBenchmark ? false }: +let + inherit (nixpkgs) pkgs; + name = "lish"; + haskellPackages = pkgs.haskellPackages; + variant = if doBenchmark + then pkgs.haskell.lib.doBenchmark + else pkgs.lib.id; + drv = haskellPackages.callCabal2nix name ./. {}; +in +{ + lish = drv; + shell = haskellPackages.shellFor { + # generate hoogle doc + withHoogle = true; + packages = p: [drv]; + # packages dependencies (by default haskellPackages) + buildInputs = with haskellPackages; + [ hlint + ghcid + cabal-install + cabal2nix + hindent + # # if you want to add some system lib like ncurses + # # you could by writing it like: + # pkgs.ncurses + ]; + # nice prompt for the nix-shell + shellHook = '' + export PS1="\n\[[${name}:\033[1;32m\]\W\[\033[0m\]]> " + ''; + }; +} diff --git a/lish-benchmark.html b/lish-benchmark.html new file mode 100644 index 0000000..3db48ae --- /dev/null +++ b/lish-benchmark.html @@ -0,0 +1,647 @@ + + + + + criterion report + + + + + + + + + +
+
+

criterion performance measurements

+ +

overview

+ +

want to understand this report?

+ +
+ +

parseCmd (foo "bar")

+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
lower boundestimateupper bound
OLS regressionxxxxxxxxx
R² goodness-of-fitxxxxxxxxx
Mean execution time4.28104689513341e-64.52654834683996e-64.90588781266136e-6
Standard deviation1.0625068410346834e-61.2545845308314575e-61.7504580108253014e-6
+ + +

Outlying measurements have severe + (0.9824354319909373%) + effect on estimated standard deviation.

+
+

parseCmd (f (f ..28x...))

+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
lower boundestimateupper bound
OLS regressionxxxxxxxxx
R² goodness-of-fitxxxxxxxxx
Mean execution time5.5674492706428895e-56.147631818924635e-57.032176389854423e-5
Standard deviation1.475909426326071e-52.5348526620781456e-53.795255320003821e-5
+ + +

Outlying measurements have severe + (0.9914806816493408%) + effect on estimated standard deviation.

+
+ +

understanding this report

+ +

In this report, each function benchmarked by criterion is assigned + a section of its own. The charts in each section are active; if + you hover your mouse over data points and annotations, you will see + more details.

+ +
    +
  • The chart on the left is a + kernel + density estimate (also known as a KDE) of time + measurements. This graphs the probability of any given time + measurement occurring. A spike indicates that a measurement of a + particular time occurred; its height indicates how often that + measurement was repeated.
  • + +
  • The chart on the right is the raw data from which the kernel + density estimate is built. The x axis indicates the + number of loop iterations, while the y axis shows measured + execution time for the given number of loop iterations. The + line behind the values is the linear regression prediction of + execution time for a given number of iterations. Ideally, all + measurements will be on (or very near) this line.
  • +
+ +

Under the charts is a small table. + The first two rows are the results of a linear regression run + on the measurements displayed in the right-hand chart.

+ +
    +
  • OLS regression indicates the + time estimated for a single loop iteration using an ordinary + least-squares regression model. This number is more accurate + than the mean estimate below it, as it more effectively + eliminates measurement overhead and other constant factors.
  • +
  • R² goodness-of-fit is a measure of how + accurately the linear regression model fits the observed + measurements. If the measurements are not too noisy, R² + should lie between 0.99 and 1, indicating an excellent fit. If + the number is below 0.99, something is confounding the accuracy + of the linear model.
  • +
  • Mean execution time and standard deviation are + statistics calculated from execution time + divided by number of iterations.
  • +
+ +

We use a statistical technique called + the bootstrap + to provide confidence intervals on our estimates. The + bootstrap-derived upper and lower bounds on estimates let you see + how accurate we believe those estimates to be. (Hover the mouse + over the table headers to see the confidence levels.)

+ +

A noisy benchmarking environment can cause some or many + measurements to fall far from the mean. These outlying + measurements can have a significant inflationary effect on the + estimate of the standard deviation. We calculate and display an + estimate of the extent to which the standard deviation has been + inflated by outliers.

+ + + +
+
+ + + diff --git a/nixpkgs.nix b/nixpkgs.nix new file mode 100644 index 0000000..22535e6 --- /dev/null +++ b/nixpkgs.nix @@ -0,0 +1 @@ +import (fetchTarball https://github.com/NixOS/nixpkgs/archive/20.03.tar.gz) {} diff --git a/release.nix b/release.nix new file mode 100644 index 0000000..8923a74 --- /dev/null +++ b/release.nix @@ -0,0 +1,4 @@ +let + def = import ./. {}; +in + { lish = def.lish; } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..0d9af5e --- /dev/null +++ b/shell.nix @@ -0,0 +1 @@ +(import ./. {}).shell diff --git a/src/Lish/InternalCommands.hs b/src/Lish/InternalCommands.hs index 743edf6..22ed206 100644 --- a/src/Lish/InternalCommands.hs +++ b/src/Lish/InternalCommands.hs @@ -88,8 +88,8 @@ lnot [Bool x] = return (Bool (not x)) lnot _ = evalErr "not need a boolean" toWaitingStream :: ReduceUnawareCommand -toWaitingStream [Stream (Just h) ] = return (WaitingStream (Just h)) -toWaitingStream _ = return Void +toWaitingStream [Stream (Just h)] = return (WaitingStream (Just h)) +toWaitingStream _ = return Void bintest :: (Integer -> Integer -> Bool) -> ReduceUnawareCommand bintest f [Num x,Num y] = return $ Bool (f x y) diff --git a/tutorial.md b/tutorial.md new file mode 100644 index 0000000..9f66b1d --- /dev/null +++ b/tutorial.md @@ -0,0 +1,98 @@ + +Thanks for using the stack template `tasty-travis`! This file is here to guide +you through customizing the template files. + +This template allows you to start a simple Haskell project, either to create a +library or an application. It offers you the choice to customize the source +directory while providing hints on the proposed hierarchy that the author uses +(inspired by other Haskell projects). + +In the following sections, I will explain how to use the template. + +1. Initial configurations +========================= + +Before you get started, there are a few things that this template couldn't +provide for you. You should: + +* Add a synopsis to `lish.cabal`. It should be a short, one sentence + explanation of your project. + +* Edit the description field in `lish.cabal` if you don't like having + the description in the `README.md` file. + +* In `lish.cabal`, the category of the project has been set as 'Test'. + You might wish to change it to a more descriptive value. A list of + categories that you can use for the project is available on Hackage at + . Alternatively, you might prefer using + a name from the shorter list at + . + +* If you haven't provided the `author-email`, `author-name`, and + `github-username` to the `config.yaml` global file, you will have to search + for "TODO" markup and complete this information in `lish.cabal` and/or + in `LICENSE`. + +2. Creating the git repository +============================== + +If this project is a subdirectory of a larger project with an existing version +control or you want to use another version control system or another setup, +then you can ignore this section. + +From the root directory of the project (the directory of this file) you will +need to run the following three commands: + + git init + git add . + git commit -m "Initial commit" + +Now you can create a repository on GitHub to publish the code. + +Note that this file is excluded from the repository by being included in the +`.gitignore` file. If you want this file to be tracked, you can remove the +line `/tutorial.md` from that file. + +3. Testing the initial code +=========================== + +These are the stack commands you will likely use the most: + +``` sh +# Build the project. +stack build + +# Run the binary +stack exec lish-exe + +# Run the test suite. +stack test + +# Run the benchmarks. +stack bench + +# Generate documentation. +stack haddock +``` + +4. Customizing +============== + +As you see, the template creates both a library and a binary and tests the +library using two test suites (doctests from comments and tests with Tasty). +Both test suites can test both properties and expected testcases. Finally, +the template also offers a way to benchmark the code. + +Your project might differ significantly from this template. For example, you +might want to have a different number of executables. In that case, you should +remove/add more executable stanzas in `lish.cabal`. + +Similarly, if you don't want both test suites, you can remove one of the +stanzas. You could do the same for the benchmarks. + +*More importantly* you might want to change the contents of the library. +Rename `src/Lib` to whatever you want your top-module to be, usually the name +of your project but using `CamelCase`. Don't forget to change this name in all +places where it is referenced (executable(s), test(s) and benchmark(s)). + +Thanks again, and happy hacking! \ No newline at end of file