Created
August 6, 2012 07:48
-
-
Save kazu-yamamoto/3272030 to your computer and use it in GitHub Desktop.
time benchmark
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
import Criterion.Main | |
import qualified Data.ByteString.Char8 as BS | |
import Data.Time | |
import Data.Time.Clock.POSIX | |
import Data.UnixTime | |
import Network.HTTP.Date | |
-- import System.IO | |
import System.Locale | |
import System.Posix | |
main :: IO () | |
main = do | |
et <- epochTime | |
defaultMain $ [ | |
bench "unix-time" (whnf unixTime et) | |
, bench "http-date" (whnf httpDate et) | |
, bench "time" (whnf time et) | |
] | |
{- | |
main :: IO () | |
main = do | |
putStrLn "epochTime" >> hFlush stdout | |
et <- epochTime | |
BS.hPutStrLn stdout $ unixTime et | |
BS.hPutStrLn stdout $ httpDate et | |
BS.hPutStrLn stdout $ time et | |
-} | |
unixTime :: EpochTime -> BS.ByteString | |
unixTime = formatUnixTimeGMT webDateFormat . fromEpochTime | |
httpDate :: EpochTime -> BS.ByteString | |
httpDate = formatHTTPDate . epochTimeToHTTPDate | |
time :: EpochTime -> BS.ByteString | |
time = BS.pack . formatTime defaultTimeLocale "%a, %d %b %Y %H:%M:%S GMT" . posixSecondsToUTCTime . realToFrac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment