Benchmarking I / O operations with a criterion

I want to know how long my program reads a 12.9 MB .wavfile into memory. The function that reads the file into memory is as follows:

import qualified Data.ByteString        as BS

getSamplesFromFileAsBS :: FilePath -> IO (BS.ByteString)

It takes a file name and returns samples as ByteString. It also performs some other data validation and ignores header information. I read ByteStringsamples in mind using ByteString.hGet.

If I now compare this function with a 12.9MB file using Criterion:

bencher :: FilePath -> IO ()
bencher fp = defaultMain [
  bench "Reading all the samples from a file." $ nfIO (getSamplesFromFileAsBS fp)
  ]

I get the following result:

benchmarking Reading all the samples from a file.
time                 3.617 ms   (3.520 ms .. 3.730 ms)
                     0.989 R²   (0.981 R² .. 0.994 R²)
mean                 3.760 ms   (3.662 ms .. 3.875 ms)
std dev              354.0 μs   (259.9 μs .. 552.5 μs)
variance introduced by outliers: 62% (severely inflated)

It seems to load 12.9 MB into memory in 3.617 ms. This does not seem realistic, as it indicates that my SSD can read 3 + GB / s, which is not at all the case. What am I doing wrong?

( ) , :

runBenchmarks :: FilePath -> IO ()
runBenchmarks fp = do
  start <- getCurrentTime
  samplesBS <- getSamplesFromFileAsBS fp
  end <- samplesBS `deepseq` getCurrentTime
  print (diffUTCTime end start)

: 0.023105s. , , SSD 600 /. Criterion?

+4
1

Criterion, html. , 0,020, ( ) 0,003 .

, - .

0

Source: https://habr.com/ru/post/1675356/


All Articles