Commit 57ab0bcc authored by Gerard Ryan's avatar Gerard Ryan

v1.1.1 clone

parent de794a4c
......@@ -157,6 +157,6 @@ include Makefile.wrapper
include Makefile.benchmark #builds the benchmark framework
include Makefile.docs #populates doxgen documentation
$(BINDIR)/unittest/tests$(EXESUFFIX): $(UNITTESTMAINOBJ) $(COREUNITOBJECTS) $(EXTLIBDIR)/$(PALISADECORELIB) $(PKEUNITOBJECTS) $(EXTLIBDIR)/$(PALISADEPKELIB) $(TRAPDOORUNITOBJECTS) $(EXTLIBDIR)/$(PALISADETRAPDOORLIB) $(NTLLIB) $(GMPLIB)
$(BINDIR)/unittest/tests$(EXESUFFIX): $(UNITTESTMAINOBJ) $(COREUNITOBJECTS) $(EXTLIBDIR)/$(PALISADECORELIB) $(PKEUNITOBJECTS) $(EXTLIBDIR)/$(PALISADEPKELIB) $(NTLLIB) $(GMPLIB)
@mkdir -p $(BINDIR)/unittest
$(CC) -o $@ $(UNITTESTMAINOBJ) $(COREUNITOBJECTS) $(PKEUNITOBJECTS) $(TRAPDOORUNITOBJECTS) $(EXTLIB) -lPALISADEtrapdoor -lPALISADEpke -lPALISADEcore $(TEST_LIB) $(NTLLIB) $(GMPLIB)
$(CC) -o $@ $(UNITTESTMAINOBJ) $(COREUNITOBJECTS) $(PKEUNITOBJECTS) $(EXTLIB) -lPALISADEpke -lPALISADEcore $(TEST_LIB) $(NTLLIB) $(GMPLIB)
......@@ -22,108 +22,47 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
This code benchmarks functions of the math directory of the PALISADE lattice encryption library.
*/
#include "benchmark/benchmark_api.h"
// this file contains the magic needed to compile and benchmark all backends in the same executable
#ifndef BENCHMARK_SRC_ALLBACKENDS_H_
#define BENCHMARK_SRC_ALLBACKENDS_H_
#include <iostream>
#define _USE_MATH_DEFINES
#include "math/backend.h"
#include "utils/inttypes.h"
#include "math/nbtheory.h"
#include "math/distrgen.h"
#include "lattice/elemparams.h"
#include "lattice/ilparams.h"
#include "lattice/ildcrtparams.h"
#include "lattice/ilelement.h"
#include "math/distrgen.h"
#include "lattice/poly.h"
#include "../../src/core/lib/lattice/dcrtpoly.h"
#include "lattice/dcrtpoly.h"
#include "utils/utilities.h"
#include "vechelper.h"
#include "ElementParmsHelper.h"
using namespace std;
using namespace lbcrypto;
// add
static void add_BigVec(benchmark::State& state) {
state.PauseTiming();
BigVector a = makeVector(parmArray[state.range(0)]);
BigVector b = makeVector(parmArray[state.range(0)]);
state.ResumeTiming();
a = a+b;
}
static void BM_BigVec_Addition(benchmark::State& state) { // benchmark
while (state.KeepRunning()) {
add_BigVec(state);
}
}
DO_PARM_BENCHMARK(BM_BigVec_Addition)
// +=
static void addeq_BigVec(benchmark::State& state) {
state.PauseTiming();
BigVector a = makeVector(parmArray[state.range(0)]);
BigVector b = makeVector(parmArray[state.range(0)]);
state.ResumeTiming();
a += b;
}
static void BM_BigVec_Addeq(benchmark::State& state) { // benchmark
while (state.KeepRunning()) {
addeq_BigVec(state);
}
}
DO_PARM_BENCHMARK(BM_BigVec_Addeq)
// mult
static void mult_BigVec(benchmark::State& state) { // function
state.PauseTiming();
BigVector a = makeVector(parmArray[state.range(0)]);
BigVector b = makeVector(parmArray[state.range(0)]);
state.ResumeTiming();
a = a*b;
}
static void BM_BigVec_Multiplication(benchmark::State& state) { // benchmark
while (state.KeepRunning()) {
mult_BigVec(state);
}
}
DO_PARM_BENCHMARK(BM_BigVec_Multiplication)
// mult
static void multeq_BigVec(benchmark::State& state) { // function
state.PauseTiming();
BigVector a = makeVector(parmArray[state.range(0)]);
BigVector b = makeVector(parmArray[state.range(0)]);
state.ResumeTiming();
a *= b;
}
static void BM_BigVec_Multeq(benchmark::State& state) { // benchmark
while (state.KeepRunning()) {
multeq_BigVec(state);
}
}
DO_PARM_BENCHMARK(BM_BigVec_Multeq)
//execute the benchmarks
BENCHMARK_MAIN()
using BE2Integer = cpu_int::BigInteger<integral_dtype,BigIntegerBitLength>;
using BE2ILParams = ILParamsImpl<BE2Integer>;
using BE2ILDCRTParams = ILDCRTParams<BE2Integer>;
using BE2Vector = cpu_int::BigVectorImpl<BE2Integer>;
using BE2Poly = PolyImpl<BE2Integer, BE2Integer, BE2Vector, BE2ILParams>;
using BE2DCRTPoly = DCRTPolyImpl<BE2Integer, BE2Integer, BE2Vector, BE2ILDCRTParams>;
using BE4Integer = exp_int::xubint;
using BE4ILParams = ILParamsImpl<BE4Integer>;
using BE4ILDCRTParams = ILDCRTParams<BE4Integer>;
using BE4Vector = exp_int::xmubintvec;
using BE4Poly = PolyImpl<BE4Integer, BE4Integer, BE4Vector, BE4ILParams>;
using BE4DCRTPoly = DCRTPolyImpl<BE4Integer, BE4Integer, BE4Vector, BE4ILDCRTParams>;
using BE6Integer = NTL::myZZ;
using BE6ILParams = ILParamsImpl<BE6Integer>;
using BE6ILDCRTParams = ILDCRTParams<BE6Integer>;
using BE6Vector = NTL::myVecP<NTL::myZZ>;
using BE6Poly = PolyImpl<BE6Integer, BE6Integer, BE6Vector, BE6ILParams>;
using BE6DCRTPoly = DCRTPolyImpl<BE6Integer, BE6Integer, BE6Vector, BE6ILDCRTParams>;
#endif /* BENCHMARK_SRC_ALLBACKENDS_H_ */
......@@ -53,29 +53,27 @@ using namespace std;
using namespace lbcrypto;
#include "vechelper.h"
#include "ElementParmsHelper.h"
#include "EncryptHelper.h"
#include "lattice/elemparamfactory.h"
void BM_keygen(benchmark::State& state) { // benchmark
CryptoContext<Poly> cc;
if( state.thread_index == 0 ) {
state.PauseTiming();
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
cc->GetCyclotomicOrder(),
cc->GetModulus());
} catch( ... ) {}
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
} catch( std::exception& e ) {
state.SkipWithError( e.what() );
return;
}
try {
typename Poly::DggType dgg = Poly::DggType(4); // Create the noise generator
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
cc->GetCyclotomicOrder(),
cc->GetModulus());
} catch( ... ) {}
state.ResumeTiming();
}
while (state.KeepRunning()) {
......@@ -85,27 +83,27 @@ void BM_keygen(benchmark::State& state) { // benchmark
BENCHMARK_PARMS(BM_keygen)
static void fillrandint(vector<int64_t>& vec, PlaintextModulus mod) {
mod /= 2;
for( size_t ii=0; ii < vec.size(); ii++ )
vec[ii] = rand() % mod;
};
void BM_encrypt(benchmark::State& state) { // benchmark
CryptoContext<Poly> cc;
LPKeyPair<Poly> kp;
Ciphertext<Poly> ciphertext;
Plaintext plaintext;
auto randchar = []() -> char {
const char charset[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[ rand() % max_index ];
};
if( state.thread_index == 0 ) {
state.PauseTiming();
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
try {
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
} catch( std::exception& e ) {
state.SkipWithError( e.what() );
return;
}
try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
......@@ -113,21 +111,9 @@ void BM_encrypt(benchmark::State& state) { // benchmark
cc->GetModulus());
} catch( ... ) {}
try {
typename Poly::DggType dgg = Poly::DggType(4); // Create the noise generator
} catch( ... ) {}
size_t strSize = cc->GetRingDimension();
if( strSize == 0 ) {
state.SkipWithError( "Chunk size is 0" );
}
string shortStr(strSize,0);
std::generate_n(shortStr.begin(), strSize, randchar);
plaintext = cc->MakeStringPlaintext(shortStr);
state.ResumeTiming();
vector<int64_t> input(cc->GetRingDimension(),0);
fillrandint(input, cc->GetEncodingParams()->GetPlaintextModulus());
plaintext = cc->MakeCoefPackedPlaintext(input);
}
while (state.KeepRunning()) {
......@@ -148,21 +134,15 @@ void BM_decrypt(benchmark::State& state) { // benchmark
Plaintext plaintext;
Plaintext plaintextNew;
auto randchar = []() -> char {
const char charset[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[ rand() % max_index ];
};
if( state.thread_index == 0 ) {
state.PauseTiming();
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
try {
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
} catch( std::exception& e ) {
state.SkipWithError( e.what() );
return;
}
try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
......@@ -170,21 +150,9 @@ void BM_decrypt(benchmark::State& state) { // benchmark
cc->GetModulus());
} catch( ... ) {}
try {
typename Poly::DggType dgg = Poly::DggType(4); // Create the noise generator
} catch( ... ) {}
size_t strSize = cc->GetRingDimension();
if( strSize == 0 ) {
state.SkipWithError( "Chunk size is 0" );
}
string shortStr(strSize,0);
std::generate_n(shortStr.begin(), strSize, randchar);
plaintext = cc->MakeStringPlaintext(shortStr);
state.ResumeTiming();
vector<int64_t> input(cc->GetRingDimension(),0);
fillrandint(input, cc->GetEncodingParams()->GetPlaintextModulus());
plaintext = cc->MakeCoefPackedPlaintext(input);
}
while (state.KeepRunning()) {
......@@ -204,11 +172,15 @@ void BM_rekeygen(benchmark::State& state) { // benchmark
LPKeyPair<Poly> kp;
if( state.thread_index == 0 ) {
state.PauseTiming();
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
cc->Enable(SHE);
try {
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
cc->Enable(SHE);
} catch( std::exception& e ) {
state.SkipWithError( e.what() );
return;
}
try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
......@@ -216,13 +188,6 @@ void BM_rekeygen(benchmark::State& state) { // benchmark
cc->GetModulus());
} catch( ... ) {
}
try {
typename Poly::DggType dgg = Poly::DggType(4); // Create the noise generator
} catch( ... ) {
}
state.ResumeTiming();
}
while (state.KeepRunning()) {
......@@ -251,21 +216,15 @@ void BM_reencrypt(benchmark::State& state) { // benchmark
Plaintext plaintext;
Plaintext plaintextNew;
auto randchar = []() -> char {
const char charset[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[ rand() % max_index ];
};
if( state.thread_index == 0 ) {
state.PauseTiming();
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
try {
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
} catch( std::exception& e ) {
state.SkipWithError( e.what() );
return;
}
try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
......@@ -273,21 +232,9 @@ void BM_reencrypt(benchmark::State& state) { // benchmark
cc->GetModulus());
} catch( ... ) {}
try {
typename Poly::DggType dgg = Poly::DggType(4); // Create the noise generator
} catch( ... ) {}
size_t strSize = cc->GetRingDimension();
if( strSize == 0 ) {
state.SkipWithError( "Chunk size is 0" );
}
string shortStr(strSize,0);
std::generate_n(shortStr.begin(), strSize, randchar);
plaintext = cc->MakeStringPlaintext(shortStr);
state.ResumeTiming();
vector<int64_t> input(cc->GetRingDimension(),0);
fillrandint(input, cc->GetEncodingParams()->GetPlaintextModulus());
plaintext = cc->MakeCoefPackedPlaintext(input);
}
LPEvalKey<Poly> evalKey;
......
/**
* @author TPOC: palisade@njit.edu
*
* @copyright Copyright (c) 2017, New Jersey Institute of Technology (NJIT)
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "lattice/elemparamfactory.h"
shared_ptr<ILParams> parm_16 = ElemParamFactory::GenElemParams<ILParams,BigInteger>(M16);
shared_ptr<ILParams> parm_1024 = ElemParamFactory::GenElemParams<ILParams,BigInteger>(M1024);
shared_ptr<ILParams> parm_2048 = ElemParamFactory::GenElemParams<ILParams,BigInteger>(M2048);
shared_ptr<ILParams> parm_4096 = ElemParamFactory::GenElemParams<ILParams,BigInteger>(M4096);
shared_ptr<ILParams> parm_8192 = ElemParamFactory::GenElemParams<ILParams,BigInteger>(M8192);
shared_ptr<ILParams> parm_16384 = ElemParamFactory::GenElemParams<ILParams,BigInteger>(M16384);
shared_ptr<ILParams> parm_32768 = ElemParamFactory::GenElemParams<ILParams,BigInteger>(M32768);
shared_ptr<ILParams> parmArray[] = {
parm_16,
parm_1024,
parm_2048,
parm_4096,
parm_8192,
parm_16384,
parm_32768,
};
shared_ptr<ILNativeParams> nparm_16 = ElemParamFactory::GenElemParams<ILNativeParams,NativeInteger>(M16);
shared_ptr<ILNativeParams> nparm_1024 = ElemParamFactory::GenElemParams<ILNativeParams,NativeInteger>(M1024);
shared_ptr<ILNativeParams> nparm_2048 = ElemParamFactory::GenElemParams<ILNativeParams,NativeInteger>(M2048);
shared_ptr<ILNativeParams> nparm_4096 = ElemParamFactory::GenElemParams<ILNativeParams,NativeInteger>(M4096);
shared_ptr<ILNativeParams> nparmArray[] = {
nparm_16,
nparm_1024,
nparm_2048,
nparm_4096,
//nparm_8192,
//nparm_16384,
//nparm_32768,
};
#define DO_PARM_BENCHMARK(X) \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_16")->Arg(0); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_1024")->Arg(1); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_2048")->Arg(2); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_4096")->Arg(3); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_8192")->Arg(4); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_16384")->Arg(5); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_32768")->Arg(6);
#define DO_NATIVEPARM_BENCHMARK(X) \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("nparm_16")->Arg(0); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("nparm_1024")->Arg(1); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("nparm_2048")->Arg(2); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("nparm_4096")->Arg(3);
#define DO_PARM_BENCHMARK_TEMPLATE(X,Y) \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_16")->Arg(0); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_1024")->Arg(1); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_2048")->Arg(2); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_4096")->Arg(3); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_8192")->Arg(4); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_16384")->Arg(5); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_32768")->Arg(6);
#define DO_NATIVEPARM_BENCHMARK_TEMPLATE(X,Y) \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("nparm_16")->Arg(0); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("nparm_1024")->Arg(1); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("nparm_2048")->Arg(2); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("nparm_4096")->Arg(3);
......@@ -41,22 +41,15 @@ using namespace std;
using namespace lbcrypto;
void BM_encoding_Scalar(benchmark::State& state) {
usint m = 1024;
PlaintextModulus ptm = 128;
int64_t value = 47;
Plaintext plaintext;
if( state.thread_index == 0 ) {
state.PauseTiming();
int64_t value = 47;
usint m = 1024;
PlaintextModulus ptm = 128;
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams,BigInteger>(m);
EncodingParams ep( new EncodingParamsImpl(ptm) );
plaintext.reset( new ScalarEncoding(lp, ep, value) );
state.ResumeTiming();
}
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams>(m);
EncodingParams ep( new EncodingParamsImpl(ptm) );
while (state.KeepRunning()) {
plaintext.reset( new ScalarEncoding(lp, ep, value) );
plaintext->Encode();
}
}
......@@ -65,23 +58,16 @@ BENCHMARK(BM_encoding_Scalar);
void BM_encoding_Integer(benchmark::State& state) { // benchmark
CryptoContext<Poly> cc;
Plaintext plaintext;
usint m = 1024;
PlaintextModulus ptm = 128;
int64_t mv = 58;
if( state.thread_index == 0 ) {
state.PauseTiming();
usint m = 1024;
PlaintextModulus ptm = 128;
int64_t mv = ((int64_t)1<<33) + (int64_t)1;
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams,BigInteger>(m);
EncodingParams ep( new EncodingParamsImpl(ptm) );
plaintext.reset( new IntegerEncoding(lp, ep, mv) );
state.ResumeTiming();
}
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams>(m);
EncodingParams ep( new EncodingParamsImpl(ptm) );
while (state.KeepRunning()) {
plaintext.reset( new IntegerEncoding(lp, ep, mv) );
plaintext->Encode();
}
}
......@@ -90,26 +76,19 @@ BENCHMARK(BM_encoding_Integer);
void BM_encoding_CoefPacked(benchmark::State& state) {
Plaintext plaintext;
usint m = 1024;
PlaintextModulus ptm = 128;
PlaintextModulus half = ptm / 2;
if( state.thread_index == 0 ) {
state.PauseTiming();
usint m = 1024;
PlaintextModulus ptm = 128;
int64_t mv = ((int64_t)1<<33) + (int64_t)1;
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams>(m);
EncodingParams ep( new EncodingParamsImpl(ptm) );
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams,BigInteger>(m);
EncodingParams ep( new EncodingParamsImpl(ptm) );
vector<int64_t> intvec;
for( usint ii=0; ii<m/2; ii++)
intvec.push_back( rand() % ptm );
plaintext.reset( new CoefPackedEncoding(lp,ep,intvec) );
state.ResumeTiming();
}
vector<int64_t> intvec;
for( usint ii=0; ii<m/2; ii++)
intvec.push_back( rand() % half );
while (state.KeepRunning()) {
plaintext.reset( new CoefPackedEncoding(lp,ep,intvec) );
plaintext->Encode();
}
}
......@@ -123,29 +102,22 @@ void BM_encoding_PackedIntPlaintext(benchmark::State& state) {
std::vector<uint64_t> vectorOfInts1 = { 1,2,3,4,5,6,7,8,0,0 };
if( state.thread_index == 0 ) {
state.PauseTiming();
usint m = 22;
PlaintextModulus p = 89;
BigInteger modulusP(p);
BigInteger modulusQ("955263939794561");
BigInteger squareRootOfRoot("941018665059848");
BigInteger bigmodulus("80899135611688102162227204937217");
BigInteger bigroot("77936753846653065954043047918387");
usint m = 22;
PlaintextModulus p = 89;
BigInteger modulusP(p);
BigInteger modulusQ("955263939794561");
BigInteger squareRootOfRoot("941018665059848");
BigInteger bigmodulus("80899135611688102162227204937217");
BigInteger bigroot("77936753846653065954043047918387");
auto cycloPoly = GetCyclotomicPolynomial<BigVector, BigInteger>(m, modulusQ);
ChineseRemainderTransformArb<BigInteger, BigVector>::SetCylotomicPolynomial(cycloPoly, modulusQ);
auto cycloPoly = GetCyclotomicPolynomial<BigVector, BigInteger>(m, modulusQ);
ChineseRemainderTransformArb<BigInteger, BigVector>::SetCylotomicPolynomial(cycloPoly, modulusQ);
lp.reset(new ILParams(m, modulusQ, squareRootOfRoot, bigmodulus, bigroot));
ep.reset(new EncodingParamsImpl(p,8));
state.ResumeTiming();
}
lp.reset(new ILParams(m, modulusQ, squareRootOfRoot, bigmodulus, bigroot));
ep.reset(new EncodingParamsImpl(p,8));
while (state.KeepRunning()) {
state.PauseTiming();
plaintext.reset( new PackedEncoding(lp,ep,vectorOfInts1) );
state.ResumeTiming();
plaintext->Encode();
}
......@@ -165,8 +137,6 @@ void BM_encoding_PackedIntPlaintext_SetParams(benchmark::State& state) {
std::vector<uint64_t> vectorOfInts1 = { 1,2,3,4,5,6,7,8,0,0 };
if( state.thread_index == 0 ) {
state.PauseTiming();
BigInteger modulusQ("955263939794561");
BigInteger squareRootOfRoot("941018665059848");
BigInteger bigmodulus("80899135611688102162227204937217");
......@@ -178,12 +148,10 @@ void BM_encoding_PackedIntPlaintext_SetParams(benchmark::State& state) {
lp.reset(new ILParams(m, modulusQ, squareRootOfRoot, bigmodulus, bigroot));
ep.reset(new EncodingParamsImpl(p,8));
state.ResumeTiming();
}
while (state.KeepRunning()) {
PackedEncoding::SetParams(m, p);
state.PauseTiming();
PackedEncoding::Destroy();
state.ResumeTiming();
......@@ -197,31 +165,26 @@ void BM_Encoding_String(benchmark::State& state) { // benchmark
CryptoContext<Poly> cc;
Plaintext plaintext;
if( state.thread_index == 0 ) {
state.PauseTiming();
usint m = 1024;
PlaintextModulus ptm = 256;
usint m = 1024;
PlaintextModulus ptm = 256;
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams>(m);
EncodingParams ep( new EncodingParamsImpl(ptm) );
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams,BigInteger>(m);
EncodingParams ep( new EncodingParamsImpl(ptm) );
auto randchar = []() -> char {
const char charset[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[ rand() % max_index ];
};
auto randchar = []() -> char {
const char charset[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[ rand() % max_index ];
};
string fullStr(m/2,0);
std::generate_n(fullStr.begin(), m/2, randchar);
plaintext.reset( new StringEncoding(lp,ep,fullStr) );
state.ResumeTiming();
}
string fullStr(m/2,0);
std::generate_n(fullStr.begin(), m/2, randchar);