[Agda] Does Agda2 have fast arrays?
Alan Jeffrey
ajeffrey at bell-labs.com
Mon Oct 4 18:46:48 CEST 2010
On 10/03/2010 12:59 AM, Don Stewart wrote:
> What can we do about the coercions? I suspect they make GHC sad.
Sorry, I'm being dense here -- what's the runtime penalty for
unsafeCoerce? I'd expect that most compilers implement it as a no-op.
There may be cases where ghc's optimizer can't do as good a job because
of unsafeCoerce, due to lack of type information, but I doubt that would
have much of an impact in practice.
As a dumb benchmark, I merge-sorted 20K of data, first in Agda:
1.23user 0.48system 0:01.72elapsed 99%CPU (0avgtext+0avgdata
1282352maxresident)k
0inputs+48outputs (0major+80211minor)pagefaults 0swaps
then in Haskell:
1.22user 0.64system 0:01.85elapsed 100%CPU (0avgtext+0avgdata
1282368maxresident)k
0inputs+48outputs (0major+80212minor)pagefaults 0swaps
This is a deliberately (honest!) not-very-clever sorting algorithm which
generates lots of cons cells. I ran it with 2G heap to minimize the
impact of the GC (about 13% GC time).
Of course, you can argue that this isn't a very good benchmark, as it is
more memory-intensive than cpu-intensive. But it's looking to me like
the Agda overhead is pretty insignificant. There may be other reasons
for wanting less coercion though, e.g. less retypechecking, targeting
languages (e.g. Java) which don't have a no-op coercion...
A.
-------------- next part --------------
{-# OPTIONS --no-termination-check #-}
open import Coinduction using ( â ; â¯_ )
open import Data.Char using ( Char )
open import Data.Bool using ( Bool ; true ; false )
open import Data.Product using ( _Ã_ ; _,_ )
open import IO.Primitive using ( getContents ; putStr ; _>>=_ )
open import Foreign.Haskell using ( Colist ; []; _â·_ )
module Main where
postulate _<_ : Char â Char â Bool
{-# COMPILED _<_ (<) #-}
Costring = Colist Char
merge : Costring â Costring â Costring
merge xs [] = xs
merge [] ys = ys
merge (x â· xs) (y â· ys) with x < y
... | true = x ⷠ⯠merge (â xs) (y â· ys)
... | false = y ⷠ⯠merge (x â· xs) (â ys)
split : Char â Costring â Costring â Costring â (Costring à Costring)
split x xs ys [] = (xs , ys)
split x xs ys (z â· zs) with x < z
... | true = split x xs (z ⷠ⯠ys) (â zs)
... | false = split x (z ⷠ⯠xs) ys (â zs)
sort : Costring â Costring
sort [] = []
sort (x â· xs) with split x [] [] (â xs)
... | (ys , zs) = merge (sort ys) (x ⷠ⯠sort zs)
main = getContents >>= λ x â (putStr (sort x))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Main.hs
Type: text/x-haskell
Size: 588 bytes
Desc: not available
Url : http://lists.chalmers.se/pipermail/agda/attachments/20101004/37e28275/Main.bin
More information about the Agda
mailing list