Move the Generator program into a proper benchmark

This commit is contained in:
Tissevert 2020-12-07 21:33:59 +01:00
parent 85edb2c74c
commit 2f933aec20
2 changed files with 23 additions and 7 deletions

View File

@ -49,12 +49,14 @@ executable sjw
default-language: Haskell2010
ghc-options: -Wall
executable generator
main-is: tests/Generator.hs
build-depends: base >=4.11 && <4.13
benchmark big-src
type: exitcode-stdio-1.0
main-is: benchmark/Main.hs
build-depends: base >= 4.9 && <4.15
, directory
, filepath
, random
, SJW
, time
default-language: Haskell2010
ghc-options: -Wall

View File

@ -1,9 +1,10 @@
{-# LANGUAGE NamedFieldPuns #-}
module Main where
import SJW (Path(..))
import SJW (Path(..), compile, source, sourceCode)
import Control.Monad (foldM)
import System.Directory (createDirectoryIfMissing)
import Data.Time.Clock (diffUTCTime, getCurrentTime)
import System.Directory (createDirectoryIfMissing, doesDirectoryExist)
import System.FilePath ((</>), (<.>))
import System.Random (randomRIO)
import Text.Printf (printf)
@ -26,7 +27,7 @@ addDependency path fakeModule = fakeModule {
}
destDir :: FilePath
destDir = "tests/giant"
destDir = "/tmp/SJW-benchmark/giant"
generateCode :: FakeModule -> String
generateCode (FakeModule {dependencies}) = unlines $
@ -80,4 +81,17 @@ writeFakeModule fakeModule@(FakeModule {name = Path components}) =
writeFile (directory </> head fileName <.> "js") $ generateCode fakeModule
main :: IO ()
main = generateDAG 10000 10 (50, 100) >>= mapM_ writeFakeModule
main = do
directoryExists <- doesDirectoryExist destDir
if not directoryExists
then do
createDirectoryIfMissing True destDir
generateDAG 10000 10 (50, 100) >>= mapM_ writeFakeModule
else return ()
start <- getCurrentTime
maybe (return ()) (\_ -> return ()) =<< sourceCode =<< compile (source [destDir])
end <- getCurrentTime
mapM_ putStrLn [
"Compiled 10k modules in " ++ show (diffUTCTime end start)
, "Left the fake project in " ++ destDir ++ " if you want to poke around"
]