diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-09-29 14:04:53 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-09-29 14:04:53 -0400 |
commit | a93b837393b788f9f1655e7766a0d254ecaa4452 (patch) | |
tree | 83eb01d9e457943f988d1d68b5dea740c1c8784f /Logs | |
parent | 9454f2c240ebf0e72b711fa852027b5fad4ffa33 (diff) |
Optimised git-annex branch log file timestamp parsing. 10% speedup
This sped up git annex find --not --in web from 6.64s to 5.69s.
The optimised parser is probably more like 50% faster than the general one
it replaced.
Diffstat (limited to 'Logs')
-rw-r--r-- | Logs/TimeStamp.hs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/Logs/TimeStamp.hs b/Logs/TimeStamp.hs index 0891f920b..a07b6a66d 100644 --- a/Logs/TimeStamp.hs +++ b/Logs/TimeStamp.hs @@ -1,6 +1,6 @@ {- log timestamp parsing - - - Copyright 2015 Joey Hess <id@joeyh.name> + - Copyright 2015-2016 Joey Hess <id@joeyh.name> - - Licensed under the GNU GPL version 3 or higher. -} @@ -9,22 +9,31 @@ module Logs.TimeStamp where +import Utility.PartialPrelude +import Utility.Misc + import Data.Time.Clock.POSIX import Data.Time +import Data.Ratio #if ! MIN_VERSION_time(1,5,0) import System.Locale #endif -import Control.Applicative -import Prelude {- Parses how POSIXTime shows itself: "1431286201.113452s" - Also handles the format with no fractional seconds. -} parsePOSIXTime :: String -> Maybe POSIXTime -#if MIN_VERSION_time(1,5,0) -parsePOSIXTime s = utcTimeToPOSIXSeconds <$> parseTimeM True defaultTimeLocale "%s%Qs" s -#else -parsePOSIXTime s = utcTimeToPOSIXSeconds <$> parseTime defaultTimeLocale "%s%Qs" s -#endif +parsePOSIXTime s = do + let (sn, sd) = separate (== '.') s + n <- readi sn + if null sd + then return (fromIntegral n) + else do + d <- readi sd + let r = d % (10 ^ (length sd - 1)) + return (fromIntegral n + fromRational r) + where + readi :: String -> Maybe Integer + readi = readish formatPOSIXTime :: String -> POSIXTime -> String formatPOSIXTime fmt t = formatTime defaultTimeLocale fmt (posixSecondsToUTCTime t) |