First measurement

This commit is contained in:
Abastro 2025-03-23 17:14:24 +09:00
parent e0c0af7cd2
commit eb99cddc92
2 changed files with 28 additions and 6 deletions

View file

@ -1,13 +1,33 @@
module Main (main) where
import Control.Exception
import Data.Vector qualified as V
import Poly
import System.Random
import System.TimeIt
main :: IO ()
main = do
let f :: Poly Int = Poly (V.fromList [1, 2, 3])
let g :: Poly Int = Poly (V.fromList [4, 5])
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)
do
let f :: Poly Int = Poly (V.fromList [1, 2, 3])
let g :: Poly Int = Poly (V.fromList [4, 5])
putStrLn $ "f: " <> show f <> ", g: " <> show g
putStrLn $ "f + g: " <> show (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"

View file

@ -20,6 +20,8 @@ common deps
build-depends:
base ^>=4.17.2.1,
vector,
random,
timeit,
library
import: warnings, deps