From 2f933aec20ccf8da6fdaa4f26078a3bc6a091d6e Mon Sep 17 00:00:00 2001 From: Tissevert Date: Mon, 7 Dec 2020 21:33:59 +0100 Subject: [PATCH] Move the Generator program into a proper benchmark --- SJW.cabal | 8 +++++--- tests/Generator.hs => benchmark/Main.hs | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) rename tests/Generator.hs => benchmark/Main.hs (76%) diff --git a/SJW.cabal b/SJW.cabal index 6eb397f..4bcd8b7 100644 --- a/SJW.cabal +++ b/SJW.cabal @@ -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 diff --git a/tests/Generator.hs b/benchmark/Main.hs similarity index 76% rename from tests/Generator.hs rename to benchmark/Main.hs index a4420fd..876d410 100644 --- a/tests/Generator.hs +++ b/benchmark/Main.hs @@ -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" + ]