First measurement
This commit is contained in:
parent
e0c0af7cd2
commit
eb99cddc92
2 changed files with 28 additions and 6 deletions
32
app/Main.hs
32
app/Main.hs
|
|
@ -1,13 +1,33 @@
|
||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
|
import Control.Exception
|
||||||
import Data.Vector qualified as V
|
import Data.Vector qualified as V
|
||||||
import Poly
|
import Poly
|
||||||
|
import System.Random
|
||||||
|
import System.TimeIt
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
let f :: Poly Int = Poly (V.fromList [1, 2, 3])
|
do
|
||||||
let g :: Poly Int = Poly (V.fromList [4, 5])
|
let f :: Poly Int = Poly (V.fromList [1, 2, 3])
|
||||||
putStrLn $ "f: " <> show f <> ", g: " <> show g
|
let g :: Poly Int = Poly (V.fromList [4, 5])
|
||||||
putStrLn $ "f + g: " <> show (f + g)
|
putStrLn $ "f: " <> show f <> ", g: " <> show g
|
||||||
putStrLn $ "f * g: " <> show (f * g)
|
putStrLn $ "f + g: " <> show (f + g)
|
||||||
putStrLn $ "Karatsuba f * g: " <> show (normalize $ karatsubaMult f g)
|
putStrLn $ "Naive f * g: " <> show (f * g)
|
||||||
|
putStrLn $ "Karatsuba f * g: " <> show (normalize $ karatsubaMult f g)
|
||||||
|
|
||||||
|
putStrLn ""
|
||||||
|
experimentFor 500
|
||||||
|
experimentFor 1000
|
||||||
|
where
|
||||||
|
experimentFor n = do
|
||||||
|
setStdGen $ mkStdGen 10
|
||||||
|
let randomPoly size = Poly <$> V.replicateM size (randomRIO (-100, 100))
|
||||||
|
putStrLn $ "Size " <> show n
|
||||||
|
f :: Poly Int <- randomPoly n
|
||||||
|
g :: Poly Int <- randomPoly n
|
||||||
|
putStrLn "naive:"
|
||||||
|
_ <- timeIt $ evaluate (f * g)
|
||||||
|
putStrLn "Karatsuba:"
|
||||||
|
_ <- timeIt $ evaluate (f * g)
|
||||||
|
putStrLn "Finished"
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ common deps
|
||||||
build-depends:
|
build-depends:
|
||||||
base ^>=4.17.2.1,
|
base ^>=4.17.2.1,
|
||||||
vector,
|
vector,
|
||||||
|
random,
|
||||||
|
timeit,
|
||||||
|
|
||||||
library
|
library
|
||||||
import: warnings, deps
|
import: warnings, deps
|
||||||
|
|
|
||||||
Reference in a new issue