agrafix / Spock

Another Haskell web framework for rapid development
https://www.spock.li
679 stars 56 forks source link

Trying Spock / Scotty benchmark with updated Spock version #161

Open vinothjustin opened 5 years ago

vinothjustin commented 5 years ago

Hi, I'm trying to run the benchmark(https://github.com/agrafix/Spock-scotty-benchmark) updating the Spock version to 0.13 but If I do, the metrics have gone down to ~6k request/sec from ~60k. Can you please let me know what I'm doing wrong? With the same code the scotty version works fine. Scotty-results.txt Spock-results.txt

{-# LANGUAGE OverloadedStrings #-}
module Main where

import System.Environment

import qualified Web.Scotty as Scotty
import Web.Spock
import Web.Spock.Config
import Data.Text (pack)

app :: SpockM () () () ()
app = do
  get "/echo/hello-world" $
    text "Hello World"

  get ("echo" <//> "plain" <//> var) $ \param ->
    text $ param

  get ("echo" <//> "regex" <//> var) $ \num ->
    text $ pack $ show (num::Int)

main =
    do args <- getArgs
       let port = 8181
       case args of
         ["scotty"] ->
             Scotty.scotty port $
             do Scotty.get "/echo/hello-world" $
                  Scotty.text "Hello World"
                Scotty.get "/echo/plain/:param" $
                  do p <- Scotty.param "param"
                     Scotty.text p
                Scotty.get (Scotty.regex "^/echo/regex/([0-9]+)$") $
                  do p <- Scotty.param "1"
                     Scotty.text p

         ["spock"] -> do
             cfg <- defaultSpockCfg () PCNoDatabase ()
             runSpock port (spock cfg app)

         _ -> putStrLn "Usage: ./Spock-scotty-benchmark spock|scotty"

and my cabal file changes are,

executable Spock-scotty-benchmark
  main-is:             Main.hs
  build-depends:       base >=4.12 && <4.13,
                       Spock >= 0.13,
                       scotty ==0.11.4,
                       text
  hs-source-dirs:      src
  default-language:    Haskell2010
  ghc-options:         -O3 -threaded

Any help would be highly appreciated, Thanks in advance.