forked from TechEmpower/FrameworkBenchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of te.github.com:TechEmpower/FrameworkBenchmarks
- Loading branch information
Showing
17 changed files
with
375 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Yesod Benchmarking Test | ||
|
||
This is the Yesod portion of a [benchmarking test suite](../) comparing a variety of web development platforms. | ||
|
||
* [Controllers](bench/Application.hs) | ||
* [Model](bench/config/models) | ||
|
||
## Infrastructure Software Versions | ||
The tests were run with: | ||
* GHC 7.4.1 | ||
* Yesod 1.1.9.2 | ||
|
||
## Test URLs | ||
### JSON Encoding Test | ||
|
||
http://localhost:3000/json | ||
|
||
### Data-Store/Database Mapping Test | ||
|
||
http://localhost:3000/db | ||
|
||
### Variable Query Test | ||
|
||
http://localhost:3000/db2/2 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
dist* | ||
static/tmp/ | ||
config/client_session_key.aes | ||
*.hi | ||
*.o | ||
*.sqlite3 | ||
.hsenv* | ||
yesod-devel/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{-# OPTIONS_GHC -fno-warn-orphans #-} | ||
module Application | ||
( makeApplication | ||
, makeFoundation | ||
) where | ||
|
||
import Import | ||
import Control.Monad | ||
import System.Random | ||
|
||
import qualified Database.Persist.Store | ||
import Database.Persist.Store (PersistValue (..)) | ||
import Network.HTTP.Conduit (newManager, def) | ||
import Yesod.Default.Config | ||
|
||
|
||
import Settings | ||
|
||
getJsonR :: Handler RepJson | ||
getJsonR = jsonToRepJson $ object ["message" .= ("Hello, World!" :: Text)] | ||
|
||
getDBR :: Handler RepJson | ||
getDBR = do | ||
(i, _) <- liftIO $ randomR (1, 10000) <$> newStdGen | ||
liftIO $ print i | ||
Just o <- runDB $ get $ Key $ PersistInt64 i | ||
jsonToRepJson $ object ["id" .= i, "randomNumber" .= worldRandomNumber o] | ||
|
||
getDB2R :: Int -> Handler RepJson | ||
getDB2R n = do | ||
os <- runDB $ replicateM n $ do | ||
(i, _) <- liftIO $ randomR (1, 10000) <$> newStdGen | ||
Just o <- get $ Key $ PersistInt64 i | ||
return $ object ["id" .= i, "randomNumber" .= worldRandomNumber o] | ||
|
||
jsonToRepJson $ array os | ||
|
||
mkYesodDispatch "App" resourcesApp | ||
|
||
makeApplication :: AppConfig DefaultEnv Extra -> IO Application | ||
makeApplication conf = makeFoundation conf >>= toWaiAppPlain | ||
|
||
makeFoundation :: AppConfig DefaultEnv Extra -> IO App | ||
makeFoundation conf = do | ||
manager <- newManager def | ||
dbconf <- withYamlEnvironment "config/mysql.yml" (appEnv conf) | ||
Database.Persist.Store.loadConfig >>= | ||
Database.Persist.Store.applyEnv | ||
p <- Database.Persist.Store.createPoolConfig (dbconf :: Settings.PersistConfig) | ||
let foundation = App conf p manager dbconf | ||
|
||
return foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Foundation where | ||
|
||
import Prelude | ||
import Yesod | ||
import Yesod.Default.Config | ||
import Network.HTTP.Conduit (Manager) | ||
import qualified Settings | ||
import qualified Database.Persist.Store | ||
import Database.Persist.GenericSql | ||
import Settings (Extra (..)) | ||
|
||
data App = App | ||
{ settings :: AppConfig DefaultEnv Extra | ||
, connPool :: Database.Persist.Store.PersistConfigPool Settings.PersistConfig -- ^ Database connection pool. | ||
, httpManager :: Manager | ||
, persistConfig :: Settings.PersistConfig | ||
} | ||
|
||
mkYesodData "App" $(parseRoutesFile "config/routes") | ||
|
||
type Form x = Html -> MForm App App (FormResult x, Widget) | ||
|
||
instance Yesod App where | ||
approot = ApprootMaster $ appRoot . settings | ||
|
||
instance YesodPersist App where | ||
type YesodPersistBackend App = SqlPersist | ||
runDB f = do | ||
master <- getYesod | ||
Database.Persist.Store.runPool | ||
(persistConfig master) | ||
f | ||
(connPool master) | ||
|
||
getExtra :: Handler Extra | ||
getExtra = fmap (appExtra . settings) getYesod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Import | ||
( module Import | ||
) where | ||
|
||
import Prelude as Import hiding (head, init, last, | ||
readFile, tail, writeFile) | ||
import Yesod as Import hiding (Route (..)) | ||
|
||
import Control.Applicative as Import (pure, (<$>), (<*>)) | ||
import Data.Text as Import (Text) | ||
|
||
import Foundation as Import | ||
import Model as Import | ||
import Settings as Import | ||
|
||
#if __GLASGOW_HASKELL__ >= 704 | ||
import Data.Monoid as Import | ||
(Monoid (mappend, mempty, mconcat), | ||
(<>)) | ||
#else | ||
import Data.Monoid as Import | ||
(Monoid (mappend, mempty, mconcat)) | ||
|
||
infixr 5 <> | ||
(<>) :: Monoid m => m -> m -> m | ||
(<>) = mappend | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Model where | ||
|
||
import Prelude | ||
import Yesod | ||
import Database.Persist.Quasi | ||
|
||
-- You can define all of your database entities in the entities file. | ||
-- You can find more information on persistent and how to declare entities | ||
-- at: | ||
-- http://www.yesodweb.com/book/persistent/ | ||
share [mkPersist sqlOnlySettings, mkMigrate "migrateAll"] | ||
$(persistFileWith lowerCaseSettings "config/models") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- | Settings are centralized, as much as possible, into this file. This | ||
-- includes database connection settings, static file locations, etc. | ||
-- In addition, you can configure a number of different aspects of Yesod | ||
-- by overriding methods in the Yesod typeclass. That instance is | ||
-- declared in the Foundation.hs file. | ||
module Settings where | ||
|
||
import Prelude | ||
import Database.Persist.MySQL (MySQLConf) | ||
import Yesod.Default.Config | ||
import Yesod.Default.Util | ||
import Data.Yaml | ||
|
||
type PersistConfig = MySQLConf | ||
|
||
data Extra = Extra | ||
{ | ||
} deriving Show | ||
|
||
parseExtra :: DefaultEnv -> Object -> Parser Extra | ||
parseExtra _ o = return Extra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Prelude (IO) | ||
import Yesod.Default.Config (fromArgs) | ||
import Yesod.Default.Main (defaultMain) | ||
import Settings (parseExtra) | ||
import Application (makeApplication) | ||
|
||
main :: IO () | ||
main = defaultMain (fromArgs parseExtra) makeApplication |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: bench | ||
version: 0.0.0 | ||
cabal-version: >= 1.8 | ||
build-type: Simple | ||
|
||
Flag dev | ||
Description: Turn on development settings, like auto-reload templates. | ||
Default: False | ||
|
||
Flag library-only | ||
Description: Build for use with "yesod devel" | ||
Default: False | ||
|
||
library | ||
exposed-modules: Application | ||
Foundation | ||
Import | ||
Model | ||
Settings | ||
|
||
if flag(dev) || flag(library-only) | ||
cpp-options: -DDEVELOPMENT | ||
ghc-options: -Wall -O0 | ||
else | ||
ghc-options: -Wall -O2 | ||
|
||
extensions: TemplateHaskell | ||
QuasiQuotes | ||
OverloadedStrings | ||
NoImplicitPrelude | ||
CPP | ||
MultiParamTypeClasses | ||
TypeFamilies | ||
GADTs | ||
GeneralizedNewtypeDeriving | ||
FlexibleContexts | ||
EmptyDataDecls | ||
NoMonomorphismRestriction | ||
|
||
build-depends: base >= 4 && < 5 | ||
-- , yesod-platform >= 1.1 && < 1.2 | ||
, yesod >= 1.1.5 && < 1.2 | ||
, yesod-core >= 1.1.7 && < 1.2 | ||
, yesod-default >= 1.1 && < 1.2 | ||
, text >= 0.11 && < 0.12 | ||
, persistent >= 1.1 && < 1.2 | ||
, persistent-mysql >= 1.1 && < 1.2 | ||
, persistent-template >= 1.1.1 && < 1.2 | ||
, template-haskell | ||
, monad-control >= 0.3 && < 0.4 | ||
, wai-extra >= 1.3 && < 1.4 | ||
, yaml >= 0.8 && < 0.9 | ||
, http-conduit >= 1.8 && < 1.10 | ||
, directory >= 1.1 && < 1.3 | ||
, warp >= 1.3 && < 1.4 | ||
, data-default | ||
, aeson | ||
, conduit >= 1.0 | ||
, monad-logger >= 0.3 | ||
, fast-logger >= 0.3 | ||
, random >= 1.0 | ||
|
||
executable bench | ||
if flag(library-only) | ||
Buildable: False | ||
|
||
main-is: main.hs | ||
hs-source-dirs: app | ||
build-depends: base | ||
, bench | ||
, yesod-default | ||
|
||
ghc-options: -threaded -O2 -rtsopts | ||
|
||
test-suite test | ||
type: exitcode-stdio-1.0 | ||
main-is: main.hs | ||
hs-source-dirs: tests | ||
ghc-options: -Wall | ||
|
||
build-depends: base | ||
, bench | ||
, yesod-test >= 0.3 && < 0.4 | ||
, yesod-default | ||
, yesod-core | ||
, persistent | ||
, persistent-mysql | ||
, resourcet | ||
, monad-logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
World | ||
randomNumber Int sql=randomNumber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Default: &defaults | ||
user: benchmarkdbuser | ||
password: benchmarkdbpass | ||
host: 127.0.0.1 | ||
port: 3306 | ||
database: hello_world | ||
poolsize: 10 | ||
|
||
Development: | ||
<<: *defaults | ||
|
||
Testing: | ||
<<: *defaults | ||
|
||
Staging: | ||
poolsize: 100 | ||
<<: *defaults | ||
|
||
Production: | ||
poolsize: 100 | ||
<<: *defaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/json JsonR GET | ||
/db DBR GET | ||
/db2/#Int DB2R GET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Default: &defaults | ||
host: "*4" # any IPv4 host | ||
port: 3000 | ||
approot: "http://localhost:3000" | ||
#analytics: UA-YOURCODE | ||
|
||
Development: | ||
<<: *defaults | ||
|
||
Testing: | ||
<<: *defaults | ||
|
||
Staging: | ||
<<: *defaults | ||
|
||
Production: | ||
#approot: "http://www.example.com" | ||
<<: *defaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"framework": "yesod", | ||
"tests": [{ | ||
"default": { | ||
"setup_file": "setup", | ||
"json_url": "/json", | ||
"db_url": "/db", | ||
"query_url": "/db2/", | ||
"port": 3000, | ||
"sort": 37 | ||
} | ||
}] | ||
} |
Oops, something went wrong.