lol-benches (empty) → 0.0.0.1
raw patch · 13 files changed
+1451/−0 lines, 13 filesdep +DRBGdep +MonadRandomdep +ansi-terminalsetup-changed
Dependencies added: DRBG, MonadRandom, ansi-terminal, base, containers, criterion, crypto-api, deepseq, lol, split, statistics, transformers, vector
Files
- CHANGES.md +6/−0
- Crypto/Lol/Benchmarks.hs +81/−0
- Crypto/Lol/Benchmarks/CycBenches.hs +180/−0
- Crypto/Lol/Benchmarks/Standard.hs +87/−0
- Crypto/Lol/Benchmarks/TensorBenches.hs +167/−0
- Crypto/Lol/Benchmarks/UCycBenches.hs +184/−0
- Crypto/Lol/Utils/PrettyPrint.hs +126/−0
- Crypto/Lol/Utils/PrettyPrint/Diagnostic.hs +105/−0
- Crypto/Lol/Utils/PrettyPrint/Table.hs +100/−0
- LICENSE +339/−0
- README +9/−0
- Setup.hs +2/−0
- lol-benches.cabal +65/−0
+ CHANGES.md view
@@ -0,0 +1,6 @@+Changelog for lol-benches project+================================++0.0.0.1+-----+ * Initial commit: moved benchmarks from package lol to lol-benches.
+ Crypto/Lol/Benchmarks.hs view
@@ -0,0 +1,81 @@+{-|+Module : Crypto.Lol.Benchmarks+Description : Infrastructure for benchmarking Lol.+Copyright : (c) Eric Crockett, 2011-2017+ Chris Peikert, 2011-2017+License : GPL-2+Maintainer : ecrockett0@email.com+Stability : experimental+Portability : POSIX++Infrastructure for benchmarking Lol.+-}++{-# LANGUAGE DataKinds #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}++module Crypto.Lol.Benchmarks+(Crypto.Lol.Benchmarks.bench+,benchM+,benchIO+,benchGroup+,genBenchArgs+,Bench+,Benchmark+,NFData+,addGen) where++import Control.DeepSeq+import Control.Monad.Random+import Criterion as C+import Crypto.Lol.Utils.GenArgs+import Data.Proxy++-- | Convenience function for benchmarks with an extra parameter.+addGen :: Proxy gen -> Proxy '(t,m,r) -> Proxy '(t,m,r,gen)+addGen _ _ = Proxy++-- | Wrapper for criterion's 'nf'+{-# INLINABLE bench #-}+bench :: NFData b => (a -> b) -> a -> Bench params+bench f = Bench . nf f++-- | Use when you need randomness /outside/ the benchmark.+benchM :: (forall m . (MonadRandom m) => m (Bench a)) -> Bench a+benchM = BenchM++-- | Wrapper for criterion's 'nfIO'. Use when there is randomness /inside/ the+-- benchmark.+benchIO :: NFData b => IO b -> Bench params+benchIO = Bench . nfIO++{-# INLINABLE benchGroup #-}+-- | Wrapper for criterion's 'bgroup'+benchGroup :: (Monad rnd) => String -> [rnd Benchmark] -> rnd Benchmark+benchGroup str = (bgroup str <$>) . sequence++-- | Converts a function mapping zero or more arguments to a 'Bench' @a@+-- by generating random inputs to the function+genBenchArgs :: (GenArgs bnch, ResultOf bnch ~ Bench a, MonadRandom rnd)+ => String -> bnch -> Proxy a -> rnd Benchmark+genBenchArgs s f _ = (C.bench s . unbench) <$> genArgs f++unbench :: Bench a -> Benchmarkable+unbench (Bench x) = x+unbench (BenchM _) = error "cannot unbench BenchM"++-- | Wrapper around criterion's 'Benchmarkable', with phantom parameters.+data Bench params where+ Bench :: Benchmarkable -> Bench a+ BenchM :: (forall m . (MonadRandom m) => m (Bench a)) -> Bench a++instance GenArgs (Bench params) where+ genArgs x@(Bench _) = return x+ genArgs (BenchM x) = x
+ Crypto/Lol/Benchmarks/CycBenches.hs view
@@ -0,0 +1,180 @@+{-|+Module : Crypto.Lol.Benchmarks.CycBenches+Description : Benchmarks for the 'Cyc' interface.+Copyright : (c) Eric Crockett, 2011-2017+ Chris Peikert, 2011-2017+License : GPL-2+Maintainer : ecrockett0@email.com+Stability : experimental+Portability : POSIX++Benchmarks for the 'Cyc' interface.+-}++{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE PartialTypeSignatures #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}++{-# OPTIONS_GHC -fno-warn-partial-type-signatures #-}++module Crypto.Lol.Benchmarks.CycBenches (cycBenches1, cycBenches2) where++import Control.Applicative+import Control.Monad.Random++import Crypto.Lol+import Crypto.Lol.Benchmarks+import Crypto.Lol.Cyclotomic.Tensor (TElt)+import Crypto.Lol.Types+import Crypto.Random++-- | Benchmarks for single-index operations. There must be a CRT basis for \(O_m\) over @r@.+{-# INLINABLE cycBenches1 #-}+cycBenches1 :: (Monad rnd, _) => Proxy '(t,m,r) -> Proxy gen -> rnd Benchmark+cycBenches1 ptmr pgen = benchGroup "Cyc" $ ($ ptmr) <$> [+ genBenchArgs "unzipPow" bench_unzipCycPow,+ genBenchArgs "unzipDec" bench_unzipCycDec,+ genBenchArgs "unzipCRT" bench_unzipCycCRT,+ genBenchArgs "zipWith (*)" bench_mul,+ genBenchArgs "crt" bench_crt,+ genBenchArgs "crtInv" bench_crtInv,+ genBenchArgs "l" bench_l,+ genBenchArgs "lInv" bench_lInv,+ genBenchArgs "*g Pow" bench_mulgPow,+ genBenchArgs "*g Dec" bench_mulgDec,+ genBenchArgs "*g CRT" bench_mulgCRT,+ genBenchArgs "divg Pow" bench_divgPow,+ genBenchArgs "divg Dec" bench_divgDec,+ genBenchArgs "divg CRT" bench_divgCRT,+ genBenchArgs "lift" bench_liftPow,+ genBenchArgs "error" (bench_errRounded 0.1) . addGen pgen+ ]++-- | Benchmarks for inter-ring operations. There must be a CRT basis for \(O_{m'}\) over @r@.+{-# INLINABLE cycBenches2 #-}+cycBenches2 :: (Monad rnd, _) => Proxy '(t,m,m',r) -> rnd Benchmark+cycBenches2 p = benchGroup "Cyc" $ ($ p) <$> [+ genBenchArgs "twacePow" bench_twacePow,+ genBenchArgs "twaceDec" bench_twaceDec,+ genBenchArgs "twaceCRT" bench_twaceCRT,+ genBenchArgs "embedPow" bench_embedPow,+ genBenchArgs "embedDec" bench_embedDec,+ genBenchArgs "embedCRT" bench_embedCRT+ ]++{-# INLINE bench_unzipCycPow #-}+bench_unzipCycPow :: _ => Cyc t m (r,r) -> Bench '(t,m,r)+bench_unzipCycPow = bench unzipCyc . advisePow++{-# INLINE bench_unzipCycDec #-}+bench_unzipCycDec :: _ => Cyc t m (r,r) -> Bench '(t,m,r)+bench_unzipCycDec = bench unzipCyc . adviseDec++{-# INLINE bench_unzipCycCRT #-}+bench_unzipCycCRT :: _ => Cyc t m (r,r) -> Bench '(t,m,r)+bench_unzipCycCRT = bench unzipCyc . adviseCRT++{-# INLINABLE bench_mul #-}+-- no CRT conversion, just coefficient-wise multiplication+bench_mul :: _ => Cyc t m r -> Cyc t m r -> Bench '(t,m,r)+bench_mul a b =+ let a' = adviseCRT a+ b' = adviseCRT b+ in bench (a' *) b'++{-# INLINABLE bench_crt #-}+-- convert input from Pow basis to CRT basis+bench_crt :: _ => Cyc t m r -> Bench '(t,m,r)+bench_crt = bench adviseCRT . advisePow++{-# INLINABLE bench_crtInv #-}+-- convert input from CRT basis to Pow basis+bench_crtInv :: _ => Cyc t m r -> Bench '(t,m,r)+bench_crtInv = bench advisePow . adviseCRT++{-# INLINABLE bench_l #-}+-- convert input from Dec basis to Pow basis+bench_l :: _ => Cyc t m r -> Bench '(t,m,r)+bench_l = bench advisePow . adviseDec++{-# INLINABLE bench_lInv #-}+-- convert input from Pow basis to Dec basis+bench_lInv :: _ => Cyc t m r -> Bench '(t,m,r)+bench_lInv = bench adviseDec . advisePow++{-# INLINE bench_liftPow #-}+-- lift an element in the Pow basis+bench_liftPow :: _ => Cyc t m r -> Bench '(t,m,r)+bench_liftPow = bench (liftCyc Pow) . advisePow++{-# INLINABLE bench_mulgPow #-}+-- multiply by g when input is in Pow basis+bench_mulgPow :: _ => Cyc t m r -> Bench '(t,m,r)+bench_mulgPow = bench mulG . advisePow++{-# INLINABLE bench_mulgDec #-}+-- multiply by g when input is in Dec basis+bench_mulgDec :: _ => Cyc t m r -> Bench '(t,m,r)+bench_mulgDec = bench mulG . adviseDec++{-# INLINABLE bench_mulgCRT #-}+-- multiply by g when input is in CRT basis+bench_mulgCRT :: _ => Cyc t m r -> Bench '(t,m,r)+bench_mulgCRT = bench mulG . adviseCRT++{-# INLINABLE bench_divgPow #-}+-- divide by g when input is in Pow basis+bench_divgPow :: _ => Cyc t m r -> Bench '(t,m,r)+bench_divgPow = bench divG . advisePow . mulG++{-# INLINABLE bench_divgDec #-}+-- divide by g when input is in Dec basis+bench_divgDec :: _ => Cyc t m r -> Bench '(t,m,r)+bench_divgDec = bench divG . adviseDec . mulG++{-# INLINABLE bench_divgCRT #-}+-- divide by g when input is in CRT basis+bench_divgCRT :: _ => Cyc t m r -> Bench '(t,m,r)+bench_divgCRT = bench divG . adviseCRT++{-# INLINABLE bench_errRounded #-}+-- generate a rounded error term+bench_errRounded :: forall t m r gen . (TElt t r, Fact m, CryptoRandomGen gen, _)+ => Double -> Bench '(t,m,r,gen)+bench_errRounded v = benchIO $ do+ gen <- newGenIO+ return $ evalRand (errorRounded v :: Rand (CryptoRand gen) (Cyc t m (LiftOf r))) gen++-- These need a hint on the kind of the output index. Could use a kind annotation on the forall'd var.+{-# INLINE bench_twacePow #-}+bench_twacePow :: forall t m m' r . (Fact m, _)+ => Cyc t m' r -> Bench '(t,m,m',r)+bench_twacePow = bench (twace :: Cyc t m' r -> Cyc t m r) . advisePow++{-# INLINE bench_twaceDec #-}+bench_twaceDec :: forall t m m' r . (Fact m, _)+ => Cyc t m' r -> Bench '(t,m,m',r)+bench_twaceDec = bench (twace :: Cyc t m' r -> Cyc t m r) . adviseDec++{-# INLINE bench_twaceCRT #-}+bench_twaceCRT :: forall t m m' r . (Fact m, _)+ => Cyc t m' r -> Bench '(t,m,m',r)+bench_twaceCRT = bench (twace :: Cyc t m' r -> Cyc t m r) . adviseCRT++{-# INLINE bench_embedPow #-}+bench_embedPow :: forall t m m' r . (Fact m', _)+ => Cyc t m r -> Bench '(t,m,m',r)+bench_embedPow = bench (advisePow . embed :: Cyc t m r -> Cyc t m' r) . advisePow++{-# INLINE bench_embedDec #-}+bench_embedDec :: forall t m m' r . (Fact m', _)+ => Cyc t m r -> Bench '(t,m,m',r)+bench_embedDec = bench (adviseDec . embed :: Cyc t m r -> Cyc t m' r) . adviseDec++{-# INLINE bench_embedCRT #-}+bench_embedCRT :: forall t m m' r . (Fact m', _)+ => Cyc t m r -> Bench '(t,m,m',r)+bench_embedCRT = bench (adviseCRT . embed :: Cyc t m r -> Cyc t m' r) . adviseCRT
+ Crypto/Lol/Benchmarks/Standard.hs view
@@ -0,0 +1,87 @@+{-|+Module : Crypto.Lol.Benchmarks.Standard+Description : Default high-level benchmarks for Tensor implementations.+Copyright : (c) Eric Crockett, 2011-2017+ Chris Peikert, 2011-2017+License : GPL-2+Maintainer : ecrockett0@email.com+Stability : experimental+Portability : POSIX++Default high-level benchmarks for Tensor implementations.+-}++{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE PartialTypeSignatures #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}++{-# OPTIONS_GHC -fno-warn-partial-type-signatures #-}++module Crypto.Lol.Benchmarks.Standard where++import Crypto.Lol.Benchmarks+import Crypto.Lol.Benchmarks.SimpleTensorBenches+import Crypto.Lol.Benchmarks.TensorBenches+import Crypto.Lol.Benchmarks.SimpleUCycBenches+import Crypto.Lol.Benchmarks.UCycBenches+import Crypto.Lol.Benchmarks.CycBenches+import Crypto.Lol.Factored+import Crypto.Lol.Types+import Crypto.Lol.Utils.ShowType+import Crypto.Random.DRBG++import Data.Int+import Data.Proxy++type Zq (q :: k) = ZqBasic q Int64++instance Show (ArgType HashDRBG) where+ show _ = "HashDRBG"++-- | Benchmark parameters reported in the paper. We suggest running these benchmarks+-- to quickly compare performance on your system or with your 'Tensor' backend.+{-# INLINABLE defaultBenches #-}+defaultBenches :: _ => Proxy t -> IO [Benchmark]+defaultBenches pt = sequence [+ benchGroup "Single Index" $ (($ (Proxy::Proxy HashDRBG)) . ($ pt)) <$> [+ oneIdxBenches (Proxy::Proxy '(F1024, Zq 12289)),+ oneIdxBenches (Proxy::Proxy '(F2048, Zq 12289)),+ oneIdxBenches (Proxy::Proxy '(F64*F27, Zq 3457)),+ oneIdxBenches (Proxy::Proxy '(F64*F81, Zq 10369)),+ oneIdxBenches (Proxy::Proxy '(F64*F9*F25, Zq 14401))],+ benchGroup "Twace-Embed" $ ($ pt) <$> [+ twoIdxBenches (Proxy::Proxy '(F8*F7*F13, F32*F7*F13, Zq 8737)),+ twoIdxBenches (Proxy::Proxy '(F8*F7*F13, F8*F5*F7*F13, Zq 14561)),+ twoIdxBenches (Proxy::Proxy '(F128, F128*F7*F13, Zq 23297))]+ ]++-- | Collection of all single-index operations at all levels of the library.+{-# INLINABLE oneIdxBenches #-}+oneIdxBenches :: forall t m r gen . _ => Proxy '(m,r) -> Proxy t -> Proxy gen -> IO Benchmark+oneIdxBenches _ _ pgen =+ let ptmr = Proxy :: Proxy '(t,m,r)+ in benchGroup (showType ptmr) $ (($ pgen) . ($ ptmr)) <$> [+ simpleTensorBenches1,+ tensorBenches1,+ simpleUCycBenches1,+ ucycBenches1,+ cycBenches1+ ]++-- | Collection of all inter-ring operations at all levels of the library.+{-# INLINABLE twoIdxBenches #-}+twoIdxBenches :: forall t m m' r . _ => Proxy '(m,m',r) -> Proxy t -> IO Benchmark+twoIdxBenches _ _ =+ let ptmr = Proxy :: Proxy '(t,m,m',r)+ in benchGroup (showType ptmr) $ ($ ptmr) <$> [+ simpleTensorBenches2,+ tensorBenches2,+ simpleUCycBenches2,+ ucycBenches2,+ cycBenches2+ ]
+ Crypto/Lol/Benchmarks/TensorBenches.hs view
@@ -0,0 +1,167 @@+{-|+Module : Crypto.Lol.Benchmarks.TensorBenches+Description : Benchmarks for the 'Tensor' interface.+Copyright : (c) Eric Crockett, 2011-2017+ Chris Peikert, 2011-2017+License : GPL-2+Maintainer : ecrockett0@email.com+Stability : experimental+Portability : POSIX++Benchmarks for the 'Tensor' interface.+-}++{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE PartialTypeSignatures #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}++{-# OPTIONS_GHC -fno-warn-partial-type-signatures #-}++module Crypto.Lol.Benchmarks.TensorBenches (tensorBenches1, tensorBenches2) where++import Control.Applicative+import Control.Monad.Random++import Crypto.Lol.Benchmarks+import Crypto.Lol.Prelude+import Crypto.Lol.Cyclotomic.Tensor+import Crypto.Lol.Types+import Crypto.Random++-- | Benchmarks for single-index operations. There must be a CRT basis for \(O_m\) over @r@.+{-# INLINABLE tensorBenches1 #-}+tensorBenches1 :: (Monad rnd, _) => Proxy '(t,m,r) -> Proxy gen -> rnd Benchmark+tensorBenches1 ptmr pgen = benchGroup "Tensor" $ ($ ptmr) <$> [+ genBenchArgs "unzipPow" bench_unzip,+ genBenchArgs "unzipDec" bench_unzip,+ genBenchArgs "unzipCRT" bench_unzip,+ genBenchArgs "zipWith (*)" bench_mul,+ genBenchArgs "crt" bench_crt,+ genBenchArgs "crtInv" bench_crtInv,+ genBenchArgs "l" bench_l,+ genBenchArgs "lInv" bench_lInv,+ genBenchArgs "*g Pow" bench_mulgPow,+ genBenchArgs "*g Dec" bench_mulgDec,+ genBenchArgs "*g CRT" bench_mulgCRT,+ genBenchArgs "divg Pow" bench_divgPow,+ genBenchArgs "divg Dec" bench_divgDec,+ genBenchArgs "divg CRT" bench_divgCRT,+ genBenchArgs "lift" bench_liftPow,+ genBenchArgs "error" (bench_errRounded 0.1) . addGen pgen+ ]++-- | Benchmarks for inter-ring operations. There must be a CRT basis for \(O_{m'}\) over @r@.+{-# INLINABLE tensorBenches2 #-}+tensorBenches2 :: (Monad rnd, _) => Proxy '(t,m,m',r) -> rnd Benchmark+tensorBenches2 p = benchGroup "Tensor" $ ($ p) <$> [+ genBenchArgs "twacePow" bench_twacePow,+ genBenchArgs "twaceDec" bench_twacePow, -- yes, twacePow is correct here. It's the same function!+ genBenchArgs "twaceCRT" bench_twaceCRT,+ genBenchArgs "embedPow" bench_embedPow,+ genBenchArgs "embedDec" bench_embedDec,+ genBenchArgs "embedCRT" bench_embedCRT+ ]++{-# INLINABLE bench_unzip #-}+bench_unzip :: _ => t m (r,r) -> Bench '(t,m,r)+bench_unzip = bench unzipT++{-# INLINABLE bench_mul #-}+-- no CRT conversion, just coefficient-wise multiplication+bench_mul :: _ => t m r -> t m r -> Bench '(t,m,r)+bench_mul a = bench (zipWithT (*) a)++{-# INLINABLE bench_crt #-}+-- convert input from Pow basis to CRT basis+bench_crt :: _ => t m r -> Bench '(t,m,r)+bench_crt = bench (fromJust' "TensorBenches.bench_crt" crt)++{-# INLINABLE bench_crtInv #-}+-- convert input from CRT basis to Pow basis+bench_crtInv :: _ => t m r -> Bench '(t,m,r)+bench_crtInv = bench (fromJust' "TensorBenches.bench_crtInv" crtInv)++{-# INLINABLE bench_l #-}+-- convert input from Dec basis to Pow basis+bench_l :: _ => t m r -> Bench '(t,m,r)+bench_l = bench l++{-# INLINABLE bench_lInv #-}+-- convert input from Dec basis to Pow basis+bench_lInv :: _ => t m r -> Bench '(t,m,r)+bench_lInv = bench lInv++{-# INLINABLE bench_liftPow #-}+-- lift an element in the Pow basis+bench_liftPow :: _ => t m r -> Bench '(t,m,r)+bench_liftPow = bench (fmapT lift)++{-# INLINABLE bench_mulgPow #-}+-- multiply by g when input is in Pow basis+bench_mulgPow :: _ => t m r -> Bench '(t,m,r)+bench_mulgPow = bench mulGPow++{-# INLINABLE bench_mulgDec #-}+-- multiply by g when input is in Dec basis+bench_mulgDec :: _ => t m r -> Bench '(t,m,r)+bench_mulgDec = bench mulGDec++{-# INLINABLE bench_mulgCRT #-}+-- multiply by g when input is in CRT basis+bench_mulgCRT :: _ => t m r -> Bench '(t,m,r)+bench_mulgCRT = bench (fromJust' "TensorBenches.bench_mulgCRT" mulGCRT)++{-# INLINABLE bench_divgPow #-}+-- divide by g when input is in Pow basis+bench_divgPow :: _ => t m r -> Bench '(t,m,r)+bench_divgPow = bench divGPow . mulGPow++{-# INLINABLE bench_divgDec #-}+-- divide by g when input is in Dec basis+bench_divgDec :: _ => t m r -> Bench '(t,m,r)+bench_divgDec = bench divGDec . mulGDec++{-# INLINABLE bench_divgCRT #-}+-- divide by g when input is in CRT basis+bench_divgCRT :: _ => t m r -> Bench '(t,m,r)+bench_divgCRT = bench (fromJust' "TensorBenches.bench_divgCRT" divGCRT)++{-# INLINABLE bench_errRounded #-}+-- generate a rounded error term+bench_errRounded :: forall t m r gen . (TElt t r, Fact m, CryptoRandomGen gen, _)+ => Double -> Bench '(t,m,r,gen)+bench_errRounded v = benchIO $ do+ gen <- newGenIO+ return $ evalRand+ (fmapT (roundMult one) <$>+ (tGaussianDec v :: Rand (CryptoRand gen) (t m Double)) :: Rand (CryptoRand gen) (t m (LiftOf r))) gen++-- EAC: due to GHC bug #12634, I have to give these a little more help than the corresponding functions+-- in UCyc and Cyc benches. Not a huge deal.+{-# INLINABLE bench_twacePow #-}+bench_twacePow :: forall t m m' r . (Tensor t, TElt t r, Fact m, _)+ => t m' r -> Bench '(t,m,m',r)+bench_twacePow = bench (twacePowDec :: t m' r -> t m r)++{-# INLINABLE bench_twaceCRT #-}+bench_twaceCRT :: forall t m m' r . (Tensor t, TElt t r, Fact m, _)+ => t m' r -> Bench '(t,m,m',r)+bench_twaceCRT = bench (fromJust' "TensorBenches.bench_twaceCRT" twaceCRT :: t m' r -> t m r)++{-# INLINABLE bench_embedPow #-}+bench_embedPow :: forall t m m' r . (Tensor t, TElt t r, Fact m', _)+ => t m r -> Bench '(t,m,m',r)+bench_embedPow = bench (embedPow :: t m r -> t m' r)++{-# INLINABLE bench_embedDec #-}+bench_embedDec :: forall t m m' r . (Tensor t, TElt t r, Fact m', _)+ => t m r -> Bench '(t,m,m',r)+bench_embedDec = bench (embedDec :: t m r -> t m' r)++{-# INLINABLE bench_embedCRT #-}+bench_embedCRT :: forall t m m' r . (Tensor t, TElt t r, Fact m', _)+ => t m r -> Bench '(t,m,m',r)+bench_embedCRT = bench (fromJust' "TensorBenches.bench_embedCRT" embedCRT :: t m r -> t m' r)
+ Crypto/Lol/Benchmarks/UCycBenches.hs view
@@ -0,0 +1,184 @@+{-|+Module : Crypto.Lol.Benchmarks.UCycBenches+Description : Benchmarks for the 'UCyc' interface.+Copyright : (c) Eric Crockett, 2011-2017+ Chris Peikert, 2011-2017+License : GPL-2+Maintainer : ecrockett0@email.com+Stability : experimental+Portability : POSIX++Benchmarks for the 'UCyc' interface.+-}++{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE PartialTypeSignatures #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}++{-# OPTIONS_GHC -fno-warn-partial-type-signatures #-}++module Crypto.Lol.Benchmarks.UCycBenches (ucycBenches1, ucycBenches2) where++import Control.Applicative+import Control.Monad.Random++import Crypto.Lol.Benchmarks+import Crypto.Lol.Cyclotomic.Tensor (TElt)+import Crypto.Lol.Cyclotomic.UCyc+import Crypto.Lol.Prelude+import Crypto.Lol.Types+import Crypto.Random++-- | Benchmarks for single-index operations. There must be a CRT basis for \(O_m\) over @r@.+{-# INLINABLE ucycBenches1 #-}+ucycBenches1 :: (Monad rnd, _) => Proxy '(t,m,r) -> Proxy gen -> rnd Benchmark+ucycBenches1 ptmr pgen = benchGroup "UCyc" $ ($ ptmr) <$> [+ genBenchArgs "unzipPow" bench_unzipUCycPow,+ genBenchArgs "unzipDec" bench_unzipUCycDec,+ genBenchArgs "unzipCRT" bench_unzipUCycCRT,+ genBenchArgs "zipWith (*)" bench_mul,+ genBenchArgs "crt" bench_crt,+ genBenchArgs "crtInv" bench_crtInv,+ genBenchArgs "l" bench_l,+ genBenchArgs "lInv" bench_lInv,+ genBenchArgs "*g Pow" bench_mulgPow,+ genBenchArgs "*g Dec" bench_mulgDec,+ genBenchArgs "*g CRT" bench_mulgCRT,+ genBenchArgs "divg Pow" bench_divgPow,+ genBenchArgs "divg Dec" bench_divgDec,+ genBenchArgs "divg CRT" bench_divgCRT,+ genBenchArgs "lift" bench_liftPow,+ genBenchArgs "error" (bench_errRounded 0.1) . addGen pgen+ ]++-- | Benchmarks for inter-ring operations. There must be a CRT basis for \(O_{m'}\) over @r@.+{-# INLINE ucycBenches2 #-}+ucycBenches2 :: (Monad rnd, _) => Proxy '(t,m,m',r) -> rnd Benchmark+ucycBenches2 p = benchGroup "UCyc" $ ($ p) <$> [+ genBenchArgs "twacePow" bench_twacePow,+ genBenchArgs "twaceDec" bench_twaceDec,+ genBenchArgs "twaceCRT" bench_twaceCRT,+ genBenchArgs "embedPow" bench_embedPow,+ genBenchArgs "embedDec" bench_embedDec,+ genBenchArgs "embedCRT" bench_embedCRT+ ]++{-# INLINE bench_unzipUCycPow #-}+bench_unzipUCycPow :: _ => UCyc t m P (r,r) -> Bench '(t,m,r)+bench_unzipUCycPow = bench unzipPow++{-# INLINE bench_unzipUCycDec #-}+bench_unzipUCycDec :: _ => UCyc t m D (r,r) -> Bench '(t,m,r)+bench_unzipUCycDec = bench unzipDec++{-# INLINE bench_unzipUCycCRT #-}+bench_unzipUCycCRT :: _ => UCycPC t m (r,r) -> Bench '(t,m,r)+bench_unzipUCycCRT = either (const $ error "bench_unzipUCycCRT expected a CRTC") (bench unzipCRTC)++pcToEC :: UCycPC t m r -> UCycEC t m r+pcToEC (Right x) = (Right x)++{-# INLINE bench_mul #-}+-- no CRT conversion, just coefficient-wise multiplication+bench_mul :: _ => UCycPC t m r -> UCycPC t m r -> Bench '(t,m,r)+bench_mul a b =+ let a' = pcToEC a+ b' = pcToEC b+ in bench (a' *) b'++{-# INLINE bench_crt #-}+-- convert input from Pow basis to CRT basis+bench_crt :: _ => UCyc t m P r -> Bench '(t,m,r)+bench_crt = bench toCRT++{-# INLINABLE bench_crtInv #-}+-- convert input from CRT basis to Pow basis+-- EAC: This is slow without explicitly mentioning UCRTElt. Possibly related to constraint synonym issues?+bench_crtInv :: (UCRTElt t r, _) => UCycPC t m r -> Bench '(t,m,r)+bench_crtInv (Right a) = bench toPow a++{-# INLINE bench_l #-}+-- convert input from Dec basis to Pow basis+bench_l :: _ => UCyc t m D r -> Bench '(t,m,r)+bench_l = bench toPow++{-# INLINE bench_lInv #-}+-- convert input from Pow basis to Dec basis+bench_lInv :: _ => UCyc t m P r -> Bench '(t,m,r)+bench_lInv = bench toDec++{-# INLINABLE bench_liftPow #-}+-- lift an element in the Pow basis+bench_liftPow :: _ => UCyc t m P r -> Bench '(t,m,r)+bench_liftPow = bench lift++{-# INLINABLE bench_mulgPow #-}+-- multiply by g when input is in Pow basis+bench_mulgPow :: _ => UCyc t m P r -> Bench '(t,m,r)+bench_mulgPow = bench mulG++{-# INLINABLE bench_mulgDec #-}+-- multiply by g when input is in Dec basis+bench_mulgDec :: _ => UCyc t m D r -> Bench '(t,m,r)+bench_mulgDec = bench mulG++{-# INLINABLE bench_mulgCRT #-}+-- multiply by g when input is in CRT basis+bench_mulgCRT :: _ => UCycPC t m r -> Bench '(t,m,r)+bench_mulgCRT (Right a) = bench mulG a++{-# INLINABLE bench_divgPow #-}+-- divide by g when input is in Pow basis+bench_divgPow :: _ => UCyc t m P r -> Bench '(t,m,r)+bench_divgPow = bench divGPow . mulG++{-# INLINABLE bench_divgDec #-}+-- divide by g when input is in Dec basis+bench_divgDec :: _ => UCyc t m D r -> Bench '(t,m,r)+bench_divgDec = bench divGDec . mulG++{-# INLINABLE bench_divgCRT #-}+-- divide by g when input is in CRT basis+bench_divgCRT :: _ => UCycPC t m r -> Bench '(t,m,r)+bench_divgCRT = either (const $ error "bench_divgCRT expected a CRTC") (bench divGCRTC)++{-# INLINABLE bench_errRounded #-}+-- generate a rounded error term+bench_errRounded :: forall t m r gen . (TElt t r, Fact m, CryptoRandomGen gen, _)+ => Double -> Bench '(t,m,r,gen)+bench_errRounded v = benchIO $ do+ gen <- newGenIO+ return $ evalRand (errorRounded v :: Rand (CryptoRand gen) (UCyc t m D (LiftOf r))) gen++{-# INLINE bench_twacePow #-}+bench_twacePow :: forall t m m' r . (Fact m, _)+ => UCyc t m' P r -> Bench '(t,m,m',r)+bench_twacePow = bench (twacePow :: UCyc t m' P r -> UCyc t m P r)++{-# INLINE bench_twaceDec #-}+bench_twaceDec :: forall t m m' r . (Fact m, _)+ => UCyc t m' D r -> Bench '(t,m,m',r)+bench_twaceDec = bench (twaceDec :: UCyc t m' D r -> UCyc t m D r)++{-# INLINE bench_twaceCRT #-}+bench_twaceCRT :: forall t m m' r . (Fact m, _)+ => UCycPC t m' r -> Bench '(t,m,m',r)+bench_twaceCRT (Right a) = bench (twaceCRTC :: UCyc t m' C r -> UCycPC t m r) a++{-# INLINE bench_embedPow #-}+bench_embedPow :: forall t m m' r . (Fact m', _)+ => UCyc t m P r -> Bench '(t,m,m',r)+bench_embedPow = bench (embedPow :: UCyc t m P r -> UCyc t m' P r)++{-# INLINE bench_embedDec #-}+bench_embedDec :: forall t m m' r . (Fact m', _)+ => UCyc t m D r -> Bench '(t,m,m',r)+bench_embedDec = bench (embedDec :: UCyc t m D r -> UCyc t m' D r)++{-# INLINE bench_embedCRT #-}+bench_embedCRT :: forall t m m' r . (Fact m', _)+ => UCycPC t m r -> Bench '(t,m,m',r)+bench_embedCRT (Right a) = bench (embedCRTC :: UCyc t m C r -> UCycPC t m' r) a
+ Crypto/Lol/Utils/PrettyPrint.hs view
@@ -0,0 +1,126 @@+{-|+Module : Crypto.Lol.Utils.PrettyPrint+Description : Pretty-printing for benchmark results.+Copyright : (c) Eric Crockett, 2011-2017+ Chris Peikert, 2011-2017+License : GPL-2+Maintainer : ecrockett0@email.com+Stability : experimental+Portability : POSIX++Pretty-printing for benchmark results.+-}++{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE RecordWildCards #-}++module Crypto.Lol.Utils.PrettyPrint+(getTableName+,getBenchParams+,getBenchLvl+,getBenchFunc+,getReports+,getRuntime+,col+,testName+,OptsInternal(..)+,Verb(..)) where++import Control.Monad (foldM, when)+import Control.Monad.IO.Class (MonadIO, liftIO)++import Criterion.Internal (runAndAnalyseOne)+import Criterion.Main.Options (defaultConfig)+import Criterion.Measurement (secs)+import Criterion.Monad (Criterion, withConfig)+import Criterion.Types++import Data.List.Split+import qualified Data.Map as Map+import Data.Maybe++import Statistics.Resampling.Bootstrap (Estimate(..))++-- | Verbosity of benchmark output.+data Verb = Progress -- ^ prints a '.' when each benchmark completes+ | Abridged -- ^ prints a one-line summary for each benchmark+ | Full -- ^ prints full criterion output for each benchmark+ deriving (Eq)++-- | Options for printing benchmark summary+data OptsInternal = OptsInternal+ {verb :: Verb, -- ^ Verbosity+ levels :: [String], -- ^ Which levels of Lol to benchmark+ benches :: [String], -- ^ Which operations to benchmark+ params :: [String], -- ^ Which parameters to benchmark+ redThreshold :: Double, -- ^ How many times larger a benchmark+ -- must be (compared to the minimum+ -- benchmark for that parameter,+ -- across all levels), to be printed in red+ colWidth :: Int, -- ^ Character width of data columns+ testNameWidth :: Int} -- ^ Character width of row labels++col, testName :: OptsInternal -> String+testName OptsInternal{..} = "%-" ++ show testNameWidth ++ "s "+col OptsInternal{..} = "%-" ++ show colWidth ++ "s "++parseBenchName :: String -> [String]+parseBenchName = wordsBy (=='/')++getTableName :: String -> String+getTableName = (!! 0) . parseBenchName++getBenchParams :: String -> String+getBenchParams = (!! 1) . parseBenchName++getBenchLvl :: String -> String+getBenchLvl = (!! 2) . parseBenchName++getBenchFunc :: String -> String+getBenchFunc = (!! 3) . parseBenchName++getReports :: OptsInternal -> Benchmark -> IO [Report]+getReports o = withConfig (config o) . runAndAnalyse o++config :: OptsInternal -> Config+config OptsInternal{..} = defaultConfig {verbosity = if verb == Full then Normal else Quiet}++-- | Run, and analyse, one or more benchmarks.+-- From Criterion.Internal+runAndAnalyse :: OptsInternal -> Benchmark -> Criterion [Report]+runAndAnalyse o@OptsInternal{..} bs = for o bs $ \idx desc bm -> do+ when (verb == Abridged || verb == Full) $ liftIO $ putStr $ "benchmark " ++ desc+ when (verb == Full) $ liftIO $ putStrLn ""+ (Analysed rpt) <- runAndAnalyseOne idx desc bm+ when (verb == Progress) $ liftIO $ putStr "."+ when (verb == Abridged) $ liftIO $ putStrLn $ "..." ++ secs (getRuntime rpt)+ return rpt++getRuntime :: Report -> Double+getRuntime Report{..} =+ let SampleAnalysis{..} = reportAnalysis+ (builtin, _) = splitAt 1 anRegress+ mests = map (\Regression{..} -> Map.lookup "iters" regCoeffs) builtin+ [Estimate{..}] = catMaybes mests+ in estPoint++-- | Iterate over benchmarks.+-- From Criterion.Internal+for :: MonadIO m => OptsInternal -> Benchmark -> (Int -> String -> Benchmarkable -> m a) -> m [a]+for OptsInternal{..} bs0 handle = snd <$> go (0::Int, []) ("", bs0)+ where+ select name =+ let param = getBenchParams name+ lvl = getBenchLvl name+ func = getBenchFunc name+ in (lvl `elem` levels) && (func `elem` benches) && (param `elem` params)+ go (!idx, drs) (pfx, Benchmark desc b)+ | select desc' = do+ x <- handle idx desc' b;+ return (idx + 1, x:drs)+ | otherwise = do+ liftIO $ putStrLn desc'+ return (idx, drs)+ where desc' = addPrefix pfx desc+ go (!idx,drs) (pfx, BenchGroup desc bs) =+ foldM go (idx,drs) [(addPrefix pfx desc, b) | b <- bs]
+ Crypto/Lol/Utils/PrettyPrint/Diagnostic.hs view
@@ -0,0 +1,105 @@+{-|+Module : Crypto.Lol.Utils.PrettyPrint.Diagnostic+Description : Pretty-printing for benchmark results across levels of the Lol stack.+Copyright : (c) Eric Crockett, 2011-2017+ Chris Peikert, 2011-2017+License : GPL-2+Maintainer : ecrockett0@email.com+Stability : experimental+Portability : POSIX++Pretty-printing for benchmark results across levels of the Lol stack.+-}++{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE RecordWildCards #-}++module Crypto.Lol.Utils.PrettyPrint.Diagnostic+(prettyBenches+,defaultOpts+,Opts(..)+,Verb(..)) where++--import Control.DeepSeq+--import Control.Exception (evaluate)+import Control.Monad (forM_, when)++import Criterion.Measurement (secs)+import Criterion.Types++import Crypto.Lol.Utils.PrettyPrint++import Data.List (nub, groupBy, transpose)++import System.Console.ANSI+import System.IO+import Text.Printf++data Opts = Opts+ {verb :: Verb, -- ^ Verbosity+ levels :: [String], -- ^ Which levels of Lol to benchmark. The empty list means run all levels.+ benches :: [String], -- ^ Which operations to benchmark. The empty list means run all benchmarks.+ redThreshold :: Double, -- ^ How many times larger a benchmark+ -- must be (compared to the minimum+ -- benchmark for that parameter,+ -- across all levels), to be printed in red+ colWidth :: Int, -- ^ Character width of data columns+ testNameWidth :: Int} -- ^ Character width of row labels++-- | Runs all benchmarks with verbosity 'Progress'.+defaultOpts :: Opts+defaultOpts =+ Opts {verb = Progress,+ levels = [],+ benches = [],+ redThreshold = 1.2,+ colWidth = 15,+ testNameWidth=40}++optsToInternal :: Opts -> Benchmark -> OptsInternal+optsToInternal Opts{..} bnch =+ OptsInternal{params=[getBenchParams $ head $ benchNames bnch],+ levels=if null levels+ then nub $ map getBenchLvl $ benchNames bnch+ else levels,+ benches=if null benches+ then nub $ map getBenchFunc $ benchNames bnch+ else benches,+ ..}++-- | Takes benchmark options an a benchmark group nested as params/level/op,+-- and prints a table comparing operations across all selected levels of Lol.+prettyBenches :: Opts -> Benchmark-> IO ()+prettyBenches o bnch = do+ hSetBuffering stdout NoBuffering -- for better printing of progress+ let o'@OptsInternal{..} = optsToInternal o bnch+ rpts <- getReports o' bnch+ when (verb == Progress) $ putStrLn ""+ printTable o' $ reverse rpts++printTable :: OptsInternal -> [Report] -> IO ()+printTable _ [] = return ()+printTable o rpts = do+ let colLbls = nub $ map (getBenchLvl . reportName) rpts+ printf (testName o) $ getBenchParams $ reportName $ head rpts+ mapM_ (printf (col o)) colLbls+ printf "\n"+ let rpts' = transpose $ groupBy (\a b -> getBenchLvl (reportName a) == getBenchLvl (reportName b)) rpts+ mapM_ (printRow o) rpts'+ putStrLn ""++-- See Criterion.Internal.analyseOne+printRow :: OptsInternal -> [Report] -> IO ()+printRow o@OptsInternal{..} xs@(rpt : _) = do+ printf (testName o) $ getBenchFunc $ reportName rpt+ let times = map getRuntime xs+ minTime = minimum times+ printCol t =+ if t > (redThreshold*minTime)+ then do+ setSGR [SetColor Foreground Vivid Red]+ printf (col o) $ secs t+ setSGR [Reset]+ else printf (col o) $ secs t+ forM_ times printCol+ putStrLn ""
+ Crypto/Lol/Utils/PrettyPrint/Table.hs view
@@ -0,0 +1,100 @@+{-|+Module : Crypto.Lol.Utils.PrettyPrint.Table+Description : Pretty-printing for benchmark results within a single level of the Lol stack.+Copyright : (c) Eric Crockett, 2011-2017+ Chris Peikert, 2011-2017+License : GPL-2+Maintainer : ecrockett0@email.com+Stability : experimental+Portability : POSIX++Pretty-printing for benchmark results within a single level of the Lol stack.+-}++{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE RecordWildCards #-}++module Crypto.Lol.Utils.PrettyPrint.Table+(prettyBenches+,defaultOpts+,Opts(..)+,Verb(..)) where++import Control.Monad (forM_, when)++import Criterion.Types++import Criterion.Measurement (secs)++import Crypto.Lol.Utils.PrettyPrint++import Data.List (nub, groupBy, transpose)++import System.IO+import Text.Printf+++data Opts = Opts+ {verb :: Verb, -- ^ Verbosity+ level :: String, -- ^ Which level of Lol to benchmark+ benches :: [String], -- ^ Which operations to benchmark. The empty list means run all benchmarks.+ params :: [String], -- ^ Which parameters to benchmark. The empty list means run all parameters.+ colWidth :: Int, -- ^ Character width of data columns+ testNameWidth :: Int} -- ^ Character width of row labels++optsToInternal :: Opts -> Benchmark -> OptsInternal+optsToInternal Opts{..} bnch =+ OptsInternal{params=if null params+ then nub $ map getBenchParams $ benchNames bnch+ else params,+ levels=if null level+ then nub $ map getBenchLvl $ benchNames bnch+ else [level],+ benches=if null benches+ then nub $ map getBenchFunc $ benchNames bnch+ else benches,+ redThreshold = 0,+ ..}++-- | Runs all benchmarks with verbosity 'Progress'.+defaultOpts :: Maybe String -> Opts+defaultOpts lvl =+ case lvl of+ Nothing -> go ""+ (Just l) -> go l+ where go level =+ Opts {verb = Progress,+ benches = [],+ params = [],+ colWidth = 30,+ testNameWidth=20, ..}++-- | Takes benchmark options an a benchmark group nested as params/level/op,+-- and prints a table comparing operations across all selected levels of Lol.+prettyBenches :: Opts -> Benchmark-> IO ()+prettyBenches o bnch = do+ hSetBuffering stdout NoBuffering -- for better printing of progress+ let o'@OptsInternal{..} = optsToInternal o bnch+ rpts <- getReports o' bnch+ when (verb == Progress) $ putStrLn ""+ printTable o' $ reverse rpts++printTable :: OptsInternal -> [Report] -> IO ()+printTable _ [] = return ()+printTable o rpts = do+ let colLbls = nub $ map (getBenchParams . reportName) rpts+ exName = reportName $ head rpts+ printf (testName o) $ (getTableName exName) ++ "/" ++ (getBenchLvl exName)+ mapM_ (printf (col o)) colLbls+ printf "\n"+ let rpts' = transpose $ groupBy (\a b -> getBenchParams (reportName a) == getBenchParams (reportName b)) rpts+ mapM_ (printRow o) rpts'+ putStrLn ""++-- See Criterion.Internal.analyseOne+printRow :: OptsInternal -> [Report] -> IO ()+printRow o@OptsInternal{..} xs@(rpt : _) = do+ printf (testName o) $ getBenchFunc $ reportName rpt+ let times = map (secs . getRuntime) xs+ forM_ times (printf (col o))+ putStrLn ""
+ LICENSE view
@@ -0,0 +1,339 @@+ GNU GENERAL PUBLIC LICENSE+ Version 2, June 1991++ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++ Preamble++ The licenses for most software are designed to take away your+freedom to share and change it. By contrast, the GNU General Public+License is intended to guarantee your freedom to share and change free+software--to make sure the software is free for all its users. This+General Public License applies to most of the Free Software+Foundation's software and to any other program whose authors commit to+using it. (Some other Free Software Foundation software is covered by+the GNU Lesser General Public License instead.) You can apply it to+your programs, too.++ When we speak of free software, we are referring to freedom, not+price. Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+this service if you wish), that you receive source code or can get it+if you want it, that you can change the software or use pieces of it+in new free programs; and that you know you can do these things.++ To protect your rights, we need to make restrictions that forbid+anyone to deny you these rights or to ask you to surrender the rights.+These restrictions translate to certain responsibilities for you if you+distribute copies of the software, or if you modify it.++ For example, if you distribute copies of such a program, whether+gratis or for a fee, you must give the recipients all the rights that+you have. You must make sure that they, too, receive or can get the+source code. And you must show them these terms so they know their+rights.++ We protect your rights with two steps: (1) copyright the software, and+(2) offer you this license which gives you legal permission to copy,+distribute and/or modify the software.++ Also, for each author's protection and ours, we want to make certain+that everyone understands that there is no warranty for this free+software. If the software is modified by someone else and passed on, we+want its recipients to know that what they have is not the original, so+that any problems introduced by others will not reflect on the original+authors' reputations.++ Finally, any free program is threatened constantly by software+patents. We wish to avoid the danger that redistributors of a free+program will individually obtain patent licenses, in effect making the+program proprietary. To prevent this, we have made it clear that any+patent must be licensed for everyone's free use or not licensed at all.++ The precise terms and conditions for copying, distribution and+modification follow.++ GNU GENERAL PUBLIC LICENSE+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION++ 0. This License applies to any program or other work which contains+a notice placed by the copyright holder saying it may be distributed+under the terms of this General Public License. The "Program", below,+refers to any such program or work, and a "work based on the Program"+means either the Program or any derivative work under copyright law:+that is to say, a work containing the Program or a portion of it,+either verbatim or with modifications and/or translated into another+language. (Hereinafter, translation is included without limitation in+the term "modification".) Each licensee is addressed as "you".++Activities other than copying, distribution and modification are not+covered by this License; they are outside its scope. The act of+running the Program is not restricted, and the output from the Program+is covered only if its contents constitute a work based on the+Program (independent of having been made by running the Program).+Whether that is true depends on what the Program does.++ 1. You may copy and distribute verbatim copies of the Program's+source code as you receive it, in any medium, provided that you+conspicuously and appropriately publish on each copy an appropriate+copyright notice and disclaimer of warranty; keep intact all the+notices that refer to this License and to the absence of any warranty;+and give any other recipients of the Program a copy of this License+along with the Program.++You may charge a fee for the physical act of transferring a copy, and+you may at your option offer warranty protection in exchange for a fee.++ 2. You may modify your copy or copies of the Program or any portion+of it, thus forming a work based on the Program, and copy and+distribute such modifications or work under the terms of Section 1+above, provided that you also meet all of these conditions:++ a) You must cause the modified files to carry prominent notices+ stating that you changed the files and the date of any change.++ b) You must cause any work that you distribute or publish, that in+ whole or in part contains or is derived from the Program or any+ part thereof, to be licensed as a whole at no charge to all third+ parties under the terms of this License.++ c) If the modified program normally reads commands interactively+ when run, you must cause it, when started running for such+ interactive use in the most ordinary way, to print or display an+ announcement including an appropriate copyright notice and a+ notice that there is no warranty (or else, saying that you provide+ a warranty) and that users may redistribute the program under+ these conditions, and telling the user how to view a copy of this+ License. (Exception: if the Program itself is interactive but+ does not normally print such an announcement, your work based on+ the Program is not required to print an announcement.)++These requirements apply to the modified work as a whole. If+identifiable sections of that work are not derived from the Program,+and can be reasonably considered independent and separate works in+themselves, then this License, and its terms, do not apply to those+sections when you distribute them as separate works. But when you+distribute the same sections as part of a whole which is a work based+on the Program, the distribution of the whole must be on the terms of+this License, whose permissions for other licensees extend to the+entire whole, and thus to each and every part regardless of who wrote it.++Thus, it is not the intent of this section to claim rights or contest+your rights to work written entirely by you; rather, the intent is to+exercise the right to control the distribution of derivative or+collective works based on the Program.++In addition, mere aggregation of another work not based on the Program+with the Program (or with a work based on the Program) on a volume of+a storage or distribution medium does not bring the other work under+the scope of this License.++ 3. You may copy and distribute the Program (or a work based on it,+under Section 2) in object code or executable form under the terms of+Sections 1 and 2 above provided that you also do one of the following:++ a) Accompany it with the complete corresponding machine-readable+ source code, which must be distributed under the terms of Sections+ 1 and 2 above on a medium customarily used for software interchange; or,++ b) Accompany it with a written offer, valid for at least three+ years, to give any third party, for a charge no more than your+ cost of physically performing source distribution, a complete+ machine-readable copy of the corresponding source code, to be+ distributed under the terms of Sections 1 and 2 above on a medium+ customarily used for software interchange; or,++ c) Accompany it with the information you received as to the offer+ to distribute corresponding source code. (This alternative is+ allowed only for noncommercial distribution and only if you+ received the program in object code or executable form with such+ an offer, in accord with Subsection b above.)++The source code for a work means the preferred form of the work for+making modifications to it. For an executable work, complete source+code means all the source code for all modules it contains, plus any+associated interface definition files, plus the scripts used to+control compilation and installation of the executable. However, as a+special exception, the source code distributed need not include+anything that is normally distributed (in either source or binary+form) with the major components (compiler, kernel, and so on) of the+operating system on which the executable runs, unless that component+itself accompanies the executable.++If distribution of executable or object code is made by offering+access to copy from a designated place, then offering equivalent+access to copy the source code from the same place counts as+distribution of the source code, even though third parties are not+compelled to copy the source along with the object code.++ 4. You may not copy, modify, sublicense, or distribute the Program+except as expressly provided under this License. Any attempt+otherwise to copy, modify, sublicense or distribute the Program is+void, and will automatically terminate your rights under this License.+However, parties who have received copies, or rights, from you under+this License will not have their licenses terminated so long as such+parties remain in full compliance.++ 5. You are not required to accept this License, since you have not+signed it. However, nothing else grants you permission to modify or+distribute the Program or its derivative works. These actions are+prohibited by law if you do not accept this License. Therefore, by+modifying or distributing the Program (or any work based on the+Program), you indicate your acceptance of this License to do so, and+all its terms and conditions for copying, distributing or modifying+the Program or works based on it.++ 6. Each time you redistribute the Program (or any work based on the+Program), the recipient automatically receives a license from the+original licensor to copy, distribute or modify the Program subject to+these terms and conditions. You may not impose any further+restrictions on the recipients' exercise of the rights granted herein.+You are not responsible for enforcing compliance by third parties to+this License.++ 7. If, as a consequence of a court judgment or allegation of patent+infringement or for any other reason (not limited to patent issues),+conditions are imposed on you (whether by court order, agreement or+otherwise) that contradict the conditions of this License, they do not+excuse you from the conditions of this License. If you cannot+distribute so as to satisfy simultaneously your obligations under this+License and any other pertinent obligations, then as a consequence you+may not distribute the Program at all. For example, if a patent+license would not permit royalty-free redistribution of the Program by+all those who receive copies directly or indirectly through you, then+the only way you could satisfy both it and this License would be to+refrain entirely from distribution of the Program.++If any portion of this section is held invalid or unenforceable under+any particular circumstance, the balance of the section is intended to+apply and the section as a whole is intended to apply in other+circumstances.++It is not the purpose of this section to induce you to infringe any+patents or other property right claims or to contest validity of any+such claims; this section has the sole purpose of protecting the+integrity of the free software distribution system, which is+implemented by public license practices. Many people have made+generous contributions to the wide range of software distributed+through that system in reliance on consistent application of that+system; it is up to the author/donor to decide if he or she is willing+to distribute software through any other system and a licensee cannot+impose that choice.++This section is intended to make thoroughly clear what is believed to+be a consequence of the rest of this License.++ 8. If the distribution and/or use of the Program is restricted in+certain countries either by patents or by copyrighted interfaces, the+original copyright holder who places the Program under this License+may add an explicit geographical distribution limitation excluding+those countries, so that distribution is permitted only in or among+countries not thus excluded. In such case, this License incorporates+the limitation as if written in the body of this License.++ 9. The Free Software Foundation may publish revised and/or new versions+of the General Public License from time to time. Such new versions will+be similar in spirit to the present version, but may differ in detail to+address new problems or concerns.++Each version is given a distinguishing version number. If the Program+specifies a version number of this License which applies to it and "any+later version", you have the option of following the terms and conditions+either of that version or of any later version published by the Free+Software Foundation. If the Program does not specify a version number of+this License, you may choose any version ever published by the Free Software+Foundation.++ 10. If you wish to incorporate parts of the Program into other free+programs whose distribution conditions are different, write to the author+to ask for permission. For software which is copyrighted by the Free+Software Foundation, write to the Free Software Foundation; we sometimes+make exceptions for this. Our decision will be guided by the two goals+of preserving the free status of all derivatives of our free software and+of promoting the sharing and reuse of software generally.++ NO WARRANTY++ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,+REPAIR OR CORRECTION.++ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE+POSSIBILITY OF SUCH DAMAGES.++ END OF TERMS AND CONDITIONS++ How to Apply These Terms to Your New Programs++ If you develop a new program, and you want it to be of the greatest+possible use to the public, the best way to achieve this is to make it+free software which everyone can redistribute and change under these terms.++ To do so, attach the following notices to the program. It is safest+to attach them to the start of each source file to most effectively+convey the exclusion of warranty; and each file should have at least+the "copyright" line and a pointer to where the full notice is found.++ <one line to give the program's name and a brief idea of what it does.>+ Copyright (C) <year> <name of author>++ This program is free software; you can redistribute it and/or modify+ it under the terms of the GNU General Public License as published by+ the Free Software Foundation; either version 2 of the License, or+ (at your option) any later version.++ This program is distributed in the hope that it will be useful,+ but WITHOUT ANY WARRANTY; without even the implied warranty of+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ GNU General Public License for more details.++ You should have received a copy of the GNU General Public License along+ with this program; if not, write to the Free Software Foundation, Inc.,+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.++Also add information on how to contact you by electronic and paper mail.++If the program is interactive, make it output a short notice like this+when it starts in an interactive mode:++ Gnomovision version 69, Copyright (C) year name of author+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.+ This is free software, and you are welcome to redistribute it+ under certain conditions; type `show c' for details.++The hypothetical commands `show w' and `show c' should show the appropriate+parts of the General Public License. Of course, the commands you use may+be called something other than `show w' and `show c'; they could even be+mouse-clicks or menu items--whatever suits your program.++You should also get your employer (if you work as a programmer) or your+school, if any, to sign a "copyright disclaimer" for the program, if+necessary. Here is a sample; alter the names:++ Yoyodyne, Inc., hereby disclaims all copyright interest in the program+ `Gnomovision' (which makes passes at compilers) written by James Hacker.++ <signature of Ty Coon>, 1 April 1989+ Ty Coon, President of Vice++This General Public License does not permit incorporating your program into+proprietary programs. If your program is a subroutine library, you may+consider it more useful to permit linking proprietary applications with the+library. If this is what you want to do, use the GNU Lesser General+Public License instead of this License.
+ README view
@@ -0,0 +1,9 @@+This library contains modules which benchmark different layers of Lol.+Choose which layers you want to benchmark,+and call the appropriate funtion with a proxy for the relevant parameters.++Primarily, this can be used to benchmark third-party 'Tensor' instances,+but it also includes some useful tools for writing crypto application benchmarks.++Unless you are writing your own benchmarks, you shouldn't explicitly need this+package.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ lol-benches.cabal view
@@ -0,0 +1,65 @@+name: lol-benches+-- The package version. See the Haskell package versioning policy (PVP)+-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary: +-+------- breaking API changes+-- | | +----- non-breaking API additions+-- | | | +--- code changes with no API change+version: 0.0.0.1+synopsis: A library for benchmarking <https://hackage.haskell.org/package/lol Λ ∘ λ>.+homepage: https://github.com/cpeikert/Lol+Bug-Reports: https://github.com/cpeikert/Lol/issues+license: GPL-2+license-file: LICENSE+author: Eric Crockett <ecrockett0@gmail.com>, Chris Peikert <cpeikert@alum.mit.edu>+maintainer: Eric Crockett <ecrockett0@gmail.com>+copyright: Eric Crockett, Chris Peikert+category: Crypto+stability: experimental+build-type: Simple+extra-source-files: README, CHANGES.md+cabal-version: >= 1.10+description:+ This library contains code to benchmark <https://hackage.haskell.org/package/lol Λ ∘ λ (Lol)>.+ It is designed so that third-party tensors can be easily benchmarked using the same framework.+ For examples of how to use this library, see the benchmarks for+ <https://hackage.haskell.org/package/lol-cpp lol-cpp>.+source-repository head+ type: git+ location: https://github.com/cpeikert/Lol++library+ default-language: Haskell2010+ ghc-options: -fwarn-dodgy-imports -O2 -funfolding-creation-threshold=15000 -funfolding-use-threshold=1000+ -- ghc-options: -ddump-to-file -ddump-simpl+ -- ghc-options: -dsuppress-coercions -dsuppress-type-applications -dsuppress-uniques -dsuppress-module-prefixes++ exposed-modules:+ Crypto.Lol.Benchmarks+ Crypto.Lol.Benchmarks.CycBenches+ Crypto.Lol.Benchmarks.Standard+ Crypto.Lol.Benchmarks.TensorBenches+ Crypto.Lol.Benchmarks.UCycBenches+ Crypto.Lol.Utils.PrettyPrint.Diagnostic+ Crypto.Lol.Utils.PrettyPrint.Table++ other-modules:+ Crypto.Lol.Utils.PrettyPrint++ build-depends:+ ansi-terminal,+ base >= 4.9 && < 5,+ containers,+ criterion,+ crypto-api,+ deepseq,+ DRBG,+ lol >= 0.6.0.0,+ MonadRandom,+ split,+ statistics,+ transformers,+ -- EAC: lol-benches does NOT depend on vector. However, cabal can't resolve+ -- dependencies without some help on the vector version. This is a bottleneck+ -- preventing us from putting lol-benches on stackage.+ vector < 0.12.0.0