git-annex/Git
Joey Hess 7390f08ef9 Use cryptohash rather than SHA for hashing.
This is a massive win on OSX, which doesn't have a sha256sum normally.

Only use external hash commands when the file is > 1 mb,
since cryptohash is quite close to them in speed.

SHA is still used to calculate HMACs. I don't quite understand
cryptohash's API for those.

Used the following benchmark to arrive at the 1 mb number.

1 mb file:

benchmarking sha256/internal
mean: 13.86696 ms, lb 13.83010 ms, ub 13.93453 ms, ci 0.950
std dev: 249.3235 us, lb 162.0448 us, ub 458.1744 us, ci 0.950
found 5 outliers among 100 samples (5.0%)
  4 (4.0%) high mild
  1 (1.0%) high severe
variance introduced by outliers: 10.415%
variance is moderately inflated by outliers

benchmarking sha256/external
mean: 14.20670 ms, lb 14.17237 ms, ub 14.27004 ms, ci 0.950
std dev: 230.5448 us, lb 150.7310 us, ub 427.6068 us, ci 0.950
found 3 outliers among 100 samples (3.0%)
  2 (2.0%) high mild
  1 (1.0%) high severe

2 mb file:

benchmarking sha256/internal
mean: 26.44270 ms, lb 26.23701 ms, ub 26.63414 ms, ci 0.950
std dev: 1.012303 ms, lb 925.8921 us, ub 1.122267 ms, ci 0.950
variance introduced by outliers: 35.540%
variance is moderately inflated by outliers

benchmarking sha256/external
mean: 26.84521 ms, lb 26.77644 ms, ub 26.91433 ms, ci 0.950
std dev: 347.7867 us, lb 210.6283 us, ub 571.3351 us, ci 0.950
found 6 outliers among 100 samples (6.0%)

import Crypto.Hash
import Data.ByteString.Lazy as L
import Criterion.Main
import Common

testfile :: FilePath
testfile = "/run/shm/data" -- on ram disk

main = defaultMain
        [ bgroup "sha256"
                [ bench "internal" $ whnfIO internal
                , bench "external" $ whnfIO external
                ]
        ]

sha256 :: L.ByteString -> Digest SHA256
sha256 = hashlazy

internal :: IO String
internal = show . sha256 <$> L.readFile testfile

external :: IO String
external = do
	s <- readProcess "sha256sum" [testfile]
        return $ fst $ separate (== ' ') s
2013-09-22 20:06:02 -04:00
..
AutoCorrect.hs finished where indentation changes 2012-12-13 00:24:19 -04:00
Branch.hs sync, assistant: Force push of the git-annex branch. 2013-08-29 14:27:53 -04:00
BuildVersion.hs better git version checking 2013-08-02 18:32:26 -04:00
CatFile.hs Use cryptohash rather than SHA for hashing. 2013-09-22 20:06:02 -04:00
CheckAttr.hs better git version checking 2013-08-02 18:32:26 -04:00
CheckIgnore.hs gitignore support for the assistant and watcher 2013-08-02 20:37:03 -04:00
Command.hs avoid newline translation when writing to git hash-object 2013-06-18 15:08:51 -04:00
Config.hs fix permission damage (thanks, Windows) 2013-05-11 23:54:25 -04:00
Construct.hs Unescape characters in 'file://...' URIs. 2013-08-22 11:33:16 -04:00
CurrentRepo.hs avoid more build warnings on Windows 2013-08-04 14:05:36 -04:00
DiffTree.hs Unused: bugfix 2013-08-26 13:50:09 -04:00
FileMode.hs more completely solve catKey memory leak 2013-09-19 16:41:21 -04:00
Filename.hs handle C-style escapes in Format 2011-12-23 01:05:16 -04:00
FilePath.hs get rid of __WINDOWS__, use mingw32_HOST_OS 2013-08-02 12:27:32 -04:00
GCrypt.hs better probing for gcrypt repositories using new --check option 2013-09-19 12:53:24 -04:00
HashObject.hs missed another hash-object call, disable filtering there too 2013-06-18 14:48:15 -04:00
Index.hs clean up from windows porting 2013-05-11 18:23:41 -04:00
LsFiles.hs sync, pre-commit, indirect: Avoid unnecessarily catting non-symlink files from git, which can be so large it runs out of memory. 2013-09-19 14:48:42 -04:00
LsTree.hs assistant: The ConfigMonitor left one zombie behind each time it checked for changes, now fixed. 2013-03-18 22:09:51 -04:00
Merge.hs better git version checking 2013-08-02 18:32:26 -04:00
Queue.hs Escape ':' in file/directory names to avoid it being treated as a pathspec by some git commands 2013-08-01 15:15:49 -04:00
Ref.hs include HEAD in CanPush shas 2013-05-21 20:04:38 -04:00
Remote.hs webapp: support adding existing gcrypt special remotes from removable drives 2013-09-18 15:55:31 -04:00
Sha.hs whitespace fixes 2012-12-13 00:45:27 -04:00
SharedRepository.hs Support git's core.sharedRepository configuration 2012-04-21 15:36:52 -04:00
Types.hs XMPP: Avoid redundant and unncessary pushes. Note that this breaks compatibility with previous versions of git-annex, which will refuse to accept any XMPP pushes from this version. 2013-05-21 18:24:29 -04:00
UnionMerge.hs union merge bugfix 2013-01-16 21:31:06 -04:00
UpdateIndex.hs Revert "flush stream after each write to update-index, to possibly avoid buffering issues on Windows" 2013-06-14 14:34:24 -04:00
Url.hs finished where indentation changes 2012-12-13 00:24:19 -04:00
Version.hs better git version checking 2013-08-02 18:32:26 -04:00