squeeze-1.0.2.4: src/Squeeze/Test/Performance.hs
{-
Copyright (C) 2011 Dr. Alistair Ward
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-}
{- |
[@AUTHOR@] Dr. Alistair Ward
[@DESCRIPTION@] Defines a performance-test, based on randomly generated /virtual/ files.
-}
module Squeeze.Test.Performance(
-- * Functions
run
) where
import Control.Applicative((<$>))
import Control.Arrow((&&&))
import qualified Control.Monad
import qualified Control.Monad.Writer
import qualified Factory.Math.Probability
import qualified Squeeze.Data.CommandOptions as Data.CommandOptions
import qualified Squeeze.Data.FileCombination as Data.FileCombination
import qualified Squeeze.Squeeze as Squeeze
import qualified System.IO
import qualified System.Random
{- |
* Find the best-fit, into the available space, using a set composed from the specified number of /virtual/ files.
* The files have a random size, conforming to the requested distribution.
* The generated file-name, arbitrarily reflects its size.
-}
run :: (RealFrac ratio, RealFloat f, Show f, System.Random.Random f)
=> Data.CommandOptions.CommandOptions ratio
-> Int -- ^ The number of /virtual/ files to randomly generate.
-> Factory.Math.Probability.DiscreteDistribution f
-> IO [Data.FileCombination.FileCombination]
run commandOptions fileCount probabilityDistribution = do
(bestFileCombinations, log') <- Control.Monad.Writer.runWriter . Squeeze.findBestFitWriter commandOptions . map (id &&& show) . Factory.Math.Probability.generateDiscretePopulation fileCount probabilityDistribution <$> System.Random.getStdGen
Control.Monad.when (Data.CommandOptions.verbose commandOptions) $ mapM_ (System.IO.hPutStrLn System.IO.stderr) log'
return {-to IO-monad-} bestFileCombinations