-
Notifications
You must be signed in to change notification settings - Fork 8
/
load-test.idr
48 lines (40 loc) · 1.32 KB
/
load-test.idr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Main
import Data.Bytes as B
import Data.ByteArray as BA
-- %flag C "-g3 -ggdb -O0"
%link C "array.o"
initialBuf : Bytes
initialBuf = pack . concat $ replicate 128 block
where
block : List Byte
block = [10,32,1,10,100,32,1,10,255,32,1,10,1,10,255,32,1,10,255,32,1,10,255,32,1,10]
unRLE : Bytes -> Bytes
unRLE = fst . iterateL phi (empty, Nothing)
where
phi : (Bytes, Maybe Byte) -> Byte -> Result (Bytes, Maybe Byte)
phi (bs, Nothing) b = Cont (bs, Just b)
phi (bs, Just cnt) b = Cont (bs ++ pack (replicate (cast $ prim__zextB8_Int cnt) b), Nothing)
unit : Int -> Byte -> IO ()
unit n b =
let expanded = unRLE initialBuf
in let elines = map (flip snoc b) (asciiLines expanded)
in printLn $ (show b ++ "/" ++ show n, length expanded, length elines)
alloc : Int -> Int -> IO Int
alloc x 0 = return x
alloc x i = do
-- allocate an array
arr <- BA.allocate (64 * 1024 * 1024)
-- write "i" at offset 63M
BA.pokeInt (63*1024*1024) i arr
-- read number from offset 63M
j <- BA.peekInt (63*1024*1024) arr
-- count matches
alloc (x + if i == j then 1 else 0) (i - 1)
main : IO ()
main = do
-- First allocate 4096 64M arrays to break the C heap if there's a bug
alloc 0 4096 >>= printLn
-- Then, test Bytes
traverse_ (unit n . prim__truncInt_B8) [1..n]
where
n = 8