-
-
Save Rembane/0bc2191764fd8d7c937aeb2dbfa64612 to your computer and use it in GitHub Desktop.
speedtest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.List | |
f :: Int -> Int -> Int | |
f x y = x + (y * 2) | |
sum' :: [Int] -> Int | |
sum' = foldl' (+) 0 | |
g :: Int -> Int | |
g n = sum $ map (\x -> f x (x+1)) [0..n-1] | |
h :: Int -> Int | |
h n = foldr (\x acc -> acc + f x (x+1)) [0..n-1] | |
main = do | |
print $ g 1000000 | |
print $ h 1000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun f (x y) | |
(declare (type (signed-byte 32) x y)) | |
(+ x (* y 2))) | |
(defun g (n) | |
(declare (type (signed-byte 32) n)) | |
(let ((x 0)) | |
(dotimes (y n) | |
(setq x (+ x (f y (+ y 1))))) | |
x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment