git.iko.soy/rowtype-yoga/purescript-protobuf
on v4.1.0 help sign in
66 lines 2.3 kB history raw
1module Test.Bench where
3import Prelude
5import Data.Array (range)
6import Data.ArrayBuffer.ArrayBuffer (byteLength, empty)
7import Data.ArrayBuffer.Builder (execPut)
8import Data.ArrayBuffer.DataView (whole)
9import Data.ArrayBuffer.Typed as Typed
10import Data.ArrayBuffer.Types (Float32Array)
11import Data.Float32 (fromNumber')
12import Data.Foldable (for_)
13import Effect (Effect, forE)
14import Effect.Console (log)
15import Effect.Unsafe (unsafePerformEffect)
16import Parsing (runParserT)
17import Performance.Minibench (bench, benchWith)
18import Protobuf.Internal.Decode as Decode
19import Protobuf.Internal.Encode as Encode
20import Protobuf.Internal.Runtime (manyLength)
22main :: Effect Unit
23main = do
24 log "\nWarmup bench"
25 bench \_ -> forE 0 10000 (\_ -> pure unit)
26 buf10e3 <-
27 execPut do
28 for_ (range 1 999) $ \_ -> Encode.encodeFloat (fromNumber' 1.0)
29 log "\nfloatArray 10e3"
30 benchWith 100
31 $ \_ ->
32 void $ unsafePerformEffect
33 $ runParserT (whole buf10e3) (Decode.decodeFloatArray (byteLength buf10e3))
34 buf10e4 <- empty (4 * 10000)
35 buf10e4Float :: Float32Array <- Typed.whole buf10e4
36 Typed.fill (fromNumber' 1.0) 0 9999 buf10e4Float
37 log "\nfloatArray 10e4"
38 benchWith 100
39 $ \_ ->
40 void $ unsafePerformEffect
41 $ runParserT (whole buf10e4) (Decode.decodeFloatArray (byteLength buf10e4))
42 log "\nmanyLength float 10e4"
43 benchWith 100
44 $ \_ ->
45 void $ unsafePerformEffect
46 $ runParserT (whole buf10e4) (manyLength Decode.decodeFloat (byteLength buf10e4))
47 buf10e5 <- empty (4 * 100000)
48 buf10e5Float :: Float32Array <- Typed.whole buf10e5
49 Typed.fill (fromNumber' 1.0) 0 99999 buf10e5Float
50 log "\nfloatArray 10e5"
51 benchWith 100
52 $ \_ ->
53 void $ unsafePerformEffect
54 $ runParserT (whole buf10e5) (Decode.decodeFloatArray (byteLength buf10e5))
55 log "\nmanyLength float 10e5"
56 benchWith 100
57 $ \_ ->
58 void $ unsafePerformEffect
59 $ runParserT (whole buf10e5) (manyLength Decode.decodeFloat (byteLength buf10e5))
60 buf10e6 <- empty (4 * 1000000)
61 buf10e6Float :: Float32Array <- Typed.whole buf10e6
62 Typed.fill (fromNumber' 7.0) 0 1000000 buf10e6Float
63 log "\nfloatArray 1e6"
64 benchWith 100 \_ ->
65 unsafePerformEffect do
66 void $ runParserT (whole buf10e6) (Decode.decodeFloatArray (byteLength buf10e6))