Skip to content

Instantly share code, notes, and snippets.

@Rembane
Forked from kuribas/speedtest.c
Last active June 19, 2018 08:17
Show Gist options
  • Save Rembane/0bc2191764fd8d7c937aeb2dbfa64612 to your computer and use it in GitHub Desktop.
Save Rembane/0bc2191764fd8d7c937aeb2dbfa64612 to your computer and use it in GitHub Desktop.
speedtest
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
(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