Using the ghci interpreter:
As a rough first cut, you can use the ghci
interpreter. For simplicity let's enter your definition of rev
interactively rather than from a source file. Then switch statistics mode on:
$ ghci
GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help
λ>
λ> let { rev :: [a] -> [a] ; rev [] = [] ; rev (x:xs) = (rev xs) ++ [x] }
λ>
λ> :set +s
λ>
Then we just benchmark your rev
function on 10,000 elements then 20,000 elements. The point of calling length
on the result is to force a full evaluation:
λ>
λ> length $ rev [1..10000]
10000
(1.27 secs, 4,294,492,504 bytes)
λ>
λ> length $ rev [1..20000]
20000
(5.69 secs, 17,511,565,464 bytes)
λ>
So it appears that doubling the workload makes the cost about 4 times larger. The rev
function has quadratic cost.
Why so ? well, as everything else in Haskell, the leftmost argument of operator (++) is immutable. Hence, in order to incorporate its leftmost argument into its output, the function has to duplicate it.
One can try the same benchmark using the code provided in Willem's answer. Much better... In order to get significant numbers, it is better to try it with 1,000,000 rather than just 10,000 elements.