1
0
forked from GitHub/gf-core

Use envvars in benchmark for controlling PGF/LPGF. Add readme.

This commit is contained in:
John J. Camilleri
2021-02-17 11:44:00 +01:00
parent 6a7ead0f84
commit b4fce5db59
2 changed files with 53 additions and 15 deletions

34
testsuite/lpgf/README.md Normal file
View File

@@ -0,0 +1,34 @@
# LPGF testsuite & benchmark
## Test
LPGF must be equivalent to PGF in terms of linearisation output.
Possible exceptions:
- No handling of variants (design choice)
- Rendering of missing fucntions
## Benchmark
### Compilation
Comparing PGF, LPGF along following criteria:
- Time
- Memory
- Binary file size
### Runtime (linearisation)
Comparing PGF, PGF2, LPGF along following criteria:
- Time
- Memory
### Running
```
stack build --test --bench --no-run-tests --no-run-benchmarks && time stack bench
stack build --test --bench --no-run-tests --no-run-benchmarks && time PGF_ONLY=1 stack bench
stack build --test --bench --no-run-tests --no-run-benchmarks && time LPGF_ONLY=1 stack bench
```

View File

@@ -8,12 +8,14 @@ import PGF (PGF)
import GF (compileToPGF, compileToLPGF, writePGF, writeLPGF)
import GF.Support (Options, Flags (..), Verbosity (..), noOptions, addOptions, modifyFlags)
import Control.Monad (when)
import qualified Data.List as L
import Data.Maybe (fromJust)
import Data.Maybe (fromJust, isNothing)
import qualified Data.Map as Map
import Data.Text (Text)
import Data.Time.Clock (getCurrentTime, diffUTCTime)
import System.Directory (listDirectory, getFileSize)
import System.Environment (lookupEnv)
import System.FilePath ((</>), takeBaseName, takeExtension)
import Text.Printf (printf)
@@ -35,27 +37,29 @@ main = do
mods <- map (dir </>)
. filter (\p -> grammarName `L.isPrefixOf` takeBaseName p && takeExtension p == ".gf")
<$> listDirectory dir
-- Compile
(pathPGF, pgf) <- time "compile PGF" (compilePGF mods)
(pathLPGF, lpgf) <- time "compile LPGF" (compileLPGF mods)
-- Compare filesizes
sizePGF <- getFileSize pathPGF
sizeLPGF <- getFileSize pathLPGF
printf "- PGF size: %s\n" (convertSize sizePGF)
printf "- LPGF size: %s\n" (convertSize sizeLPGF)
printf "Found modules: %s\n" (unwords mods)
-- Read trees
lns <- lines <$> readFile (dir </> treesFile)
let trees = map (fromJust . PGF.readExpr) lns
printf "Read %d trees\n" (length trees)
-- Linearise
time "linearise PGF" (return $ length $ linPGF pgf trees)
time "linearise LPGF" (return $ length $ linLPGF lpgf trees)
doPGF <- isNothing <$> lookupEnv "LPGF_ONLY"
doLPGF <- isNothing <$> lookupEnv "PGF_ONLY"
return ()
when doPGF $ do
(path, pgf) <- time "compile PGF" (compilePGF mods)
size <- getFileSize path
printf "- PGF size: %s\n" (convertSize size)
time "linearise PGF" (return $ length $ linPGF pgf trees)
return ()
when doLPGF $ do
(path, lpgf) <- time "compile LPGF" (compileLPGF mods)
size <- getFileSize path
printf "- LPGF size: %s\n" (convertSize size)
time "linearise LPGF" (return $ length $ linLPGF lpgf trees)
return ()
time :: String -> IO a -> IO a
time desc io = do