mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-23 01:52:50 -06:00
Add PFG2 linearisation to benchmark
This commit is contained in:
@@ -30,6 +30,7 @@ Comparing PGF, PGF2, LPGF along following criteria:
|
|||||||
```
|
```
|
||||||
stack build --test --bench --no-run-tests --no-run-benchmarks
|
stack build --test --bench --no-run-tests --no-run-benchmarks
|
||||||
stack bench --benchmark-arguments "+RTS -T -RTS"
|
stack bench --benchmark-arguments "+RTS -T -RTS"
|
||||||
PGF_ONLY=1 stack bench --benchmark-arguments "+RTS -T -RTS"
|
ONLY=PGF stack bench --benchmark-arguments "+RTS -T -RTS"
|
||||||
LPGF_ONLY=1 stack bench --benchmark-arguments "+RTS -T -RTS"
|
ONLY=PGF2 stack bench --benchmark-arguments "+RTS -T -RTS"
|
||||||
|
ONLY=LPGF stack bench --benchmark-arguments "+RTS -T -RTS"
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import qualified LPGF
|
import qualified LPGF
|
||||||
import LPGF (LPGF)
|
|
||||||
import qualified PGF
|
import qualified PGF
|
||||||
import PGF (PGF)
|
import qualified PGF2
|
||||||
|
|
||||||
import GF (compileToPGF, compileToLPGF, writePGF, writeLPGF)
|
import GF (compileToPGF, compileToLPGF, writePGF, writeLPGF)
|
||||||
import GF.Support (Options, Flags (..), Verbosity (..), noOptions, addOptions, modifyFlags)
|
import GF.Support (Options, Flags (..), Verbosity (..), noOptions, addOptions, modifyFlags)
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ import Data.Text (Text)
|
|||||||
import Data.Time.Clock (getCurrentTime, diffUTCTime)
|
import Data.Time.Clock (getCurrentTime, diffUTCTime)
|
||||||
import System.Directory (listDirectory, getFileSize)
|
import System.Directory (listDirectory, getFileSize)
|
||||||
import System.Environment (lookupEnv)
|
import System.Environment (lookupEnv)
|
||||||
import System.FilePath ((</>), takeBaseName, takeExtension)
|
import System.FilePath ((</>), (<.>), takeBaseName, takeExtension)
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
|
|
||||||
import GHC.Stats
|
import GHC.Stats
|
||||||
@@ -39,28 +39,39 @@ main = do
|
|||||||
mods <- map (dir </>)
|
mods <- map (dir </>)
|
||||||
. filter (\p -> grammarName `L.isPrefixOf` takeBaseName p && takeExtension p == ".gf")
|
. filter (\p -> grammarName `L.isPrefixOf` takeBaseName p && takeExtension p == ".gf")
|
||||||
<$> listDirectory dir
|
<$> listDirectory dir
|
||||||
printf "Found modules: %s\n" (unwords mods)
|
printf "Found %d modules\n" (length mods)
|
||||||
|
|
||||||
-- Read trees
|
-- Read trees
|
||||||
lns <- lines <$> readFile (dir </> treesFile)
|
lns <- lines <$> readFile (dir </> treesFile)
|
||||||
let trees = map (fromJust . PGF.readExpr) lns
|
let trees = map (fromJust . PGF.readExpr) lns
|
||||||
|
let trees2 = map (fromJust . PGF2.readExpr) lns
|
||||||
printf "Read %d trees\n" (length trees)
|
printf "Read %d trees\n" (length trees)
|
||||||
|
|
||||||
doPGF <- isNothing <$> lookupEnv "LPGF_ONLY"
|
only <- lookupEnv "ONLY"
|
||||||
doLPGF <- isNothing <$> lookupEnv "PGF_ONLY"
|
let doPGF = isNothing only || only == Just "PGF"
|
||||||
|
let doPGF2 = isNothing only || only == Just "PGF2"
|
||||||
|
let doLPGF = isNothing only || only == Just "LPGF"
|
||||||
|
|
||||||
when doPGF $ do
|
when doPGF $ do
|
||||||
(path, pgf) <- time "compile PGF" (compilePGF mods)
|
putStrLn "PGF"
|
||||||
|
(path, pgf) <- time "compile" (compilePGF mods)
|
||||||
size <- getFileSize path
|
size <- getFileSize path
|
||||||
printf "- PGF size: %s\n" (convertSize size)
|
printf "- size: %s\n" (convertSize size)
|
||||||
time "linearise PGF" (return $ length $ linPGF pgf trees)
|
time "linearise" (return $ length $ linPGF pgf trees)
|
||||||
|
return ()
|
||||||
|
|
||||||
|
when doPGF2 $ do
|
||||||
|
putStrLn "PGF2"
|
||||||
|
pgf <- PGF2.readPGF (grammarName <.> "pgf") -- might fail!
|
||||||
|
time "linearise" (return $ length $ linPGF2 pgf trees2)
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
when doLPGF $ do
|
when doLPGF $ do
|
||||||
(path, lpgf) <- time "compile LPGF" (compileLPGF mods)
|
putStrLn "LPGF"
|
||||||
|
(path, lpgf) <- time "compile" (compileLPGF mods)
|
||||||
size <- getFileSize path
|
size <- getFileSize path
|
||||||
printf "- LPGF size: %s\n" (convertSize size)
|
printf "- size: %s\n" (convertSize size)
|
||||||
time "linearise LPGF" (return $ length $ linLPGF lpgf trees)
|
time "linearise" (return $ length $ linLPGF lpgf trees)
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
stats <- getRTSStats
|
stats <- getRTSStats
|
||||||
@@ -83,23 +94,27 @@ time desc io = do
|
|||||||
-- printf "- %s: %s\n" desc (show (diffUTCTime end start))
|
-- printf "- %s: %s\n" desc (show (diffUTCTime end start))
|
||||||
-- return r
|
-- return r
|
||||||
|
|
||||||
compilePGF :: [FilePath] -> IO (FilePath, PGF)
|
compilePGF :: [FilePath] -> IO (FilePath, PGF.PGF)
|
||||||
compilePGF mods = do
|
compilePGF mods = do
|
||||||
pgf <- compileToPGF options mods
|
pgf <- compileToPGF options mods
|
||||||
files <- writePGF options pgf
|
files <- writePGF options pgf
|
||||||
return (head files, pgf)
|
return (head files, pgf)
|
||||||
|
|
||||||
compileLPGF :: [FilePath] -> IO (FilePath, LPGF)
|
compileLPGF :: [FilePath] -> IO (FilePath, LPGF.LPGF)
|
||||||
compileLPGF mods = do
|
compileLPGF mods = do
|
||||||
lpgf <- compileToLPGF options mods
|
lpgf <- compileToLPGF options mods
|
||||||
file <- writeLPGF options lpgf
|
file <- writeLPGF options lpgf
|
||||||
return (file, lpgf)
|
return (file, lpgf)
|
||||||
|
|
||||||
linPGF :: PGF -> [PGF.Expr] -> [[String]]
|
linPGF :: PGF.PGF -> [PGF.Expr] -> [[String]]
|
||||||
linPGF pgf trees =
|
linPGF pgf trees =
|
||||||
[ map (PGF.linearize pgf lang) trees | lang <- PGF.languages pgf ]
|
[ map (PGF.linearize pgf lang) trees | lang <- PGF.languages pgf ]
|
||||||
|
|
||||||
linLPGF :: LPGF -> [PGF.Expr] -> [[Text]]
|
linPGF2 :: PGF2.PGF -> [PGF2.Expr] -> [[String]]
|
||||||
|
linPGF2 pgf trees =
|
||||||
|
[ map (PGF2.linearize concr) trees | (_, concr) <- Map.toList (PGF2.languages pgf) ]
|
||||||
|
|
||||||
|
linLPGF :: LPGF.LPGF -> [PGF.Expr] -> [[Text]]
|
||||||
linLPGF lpgf trees =
|
linLPGF lpgf trees =
|
||||||
[ map (LPGF.linearizeConcreteText concr) trees | (_,concr) <- Map.toList (LPGF.concretes lpgf) ]
|
[ map (LPGF.linearizeConcreteText concr) trees | (_,concr) <- Map.toList (LPGF.concretes lpgf) ]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user