bench of toStr16, fromStr16

dev
MITSUNARI Shigeo 10 years ago
parent 0c447ebaf5
commit f75f0a3a7d
  1. 59
      sample/bench.cpp
  2. 54
      test/mont_fp_test.cpp

@ -1,6 +1,7 @@
#include <cybozu/benchmark.hpp>
#include <cybozu/option.hpp>
#include <mcl/fp.hpp>
#include <mcl/conversion.hpp>
typedef mcl::FpT<> Fp;
@ -78,6 +79,53 @@ void benchEc(size_t, int)
{
}
void benchToStr16()
{
puts("benchToStr16");
const char *tbl[] = {
"0x0",
"0x5",
"0x123",
"0x123456789012345679adbc",
"0xffffffff26f2fc170f69466a74defd8d",
"0x100000000000000000000000000000033",
"0x11ee12312312940000000000000000000000000002342343"
};
Fp::setModulo("0xffffffffffffffffffffffffffffffffffffffffffffff13");
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
std::string str;
Fp x(tbl[i]);
CYBOZU_BENCH("fp::toStr16", mcl::fp::toStr16, str, x.getUnit(), x.getUnitSize(), 16);
mpz_class y(tbl[i]);
CYBOZU_BENCH("Gmp:getStr ", mcl::Gmp::getStr, str, y, 16);
}
}
void benchFromStr16()
{
puts("benchFromStr16");
const char *tbl[] = {
"0",
"5",
"123",
"123456789012345679adbc",
"ffffffff26f2fc170f69466a74defd8d",
"100000000000000000000000000000033",
"11ee12312312940000000000000000000000000002342343"
};
Fp::setModulo("0xffffffffffffffffffffffffffffffffffffffffffffff13");
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
std::string str = tbl[i];
Fp x;
const size_t N = 64;
mcl::fp::Unit buf[N];
CYBOZU_BENCH("fp:fromStr16", mcl::fp::fromStr16, buf, N, str.c_str(), str.size());
mpz_class y;
CYBOZU_BENCH("Gmp:setStr ", mcl::Gmp::setStr, y, str, 16);
}
}
int main(int argc, char *argv[])
try
{
@ -85,11 +133,13 @@ int main(int argc, char *argv[])
int mode;
bool ecOnly;
bool fpOnly;
bool misc;
cybozu::Option opt;
opt.appendOpt(&bitSize, 0, "b", ": bitSize");
opt.appendOpt(&mode, 0, "m", ": mode(0:all, sum of 1:gmp, 2:llvm, 8:llvm+mont, 8:xbyak");
opt.appendBoolOpt(&ecOnly, "ec", ": ec only");
opt.appendBoolOpt(&fpOnly, "fp", ": fp only");
opt.appendBoolOpt(&misc, "misc", ": other benchmark");
opt.appendHelp("h", ": show this message");
if (!opt.parse(argc, argv)) {
opt.usage();
@ -101,8 +151,13 @@ int main(int argc, char *argv[])
exit(1);
}
if (mode == 0) mode = 15;
if (!ecOnly) benchFp(bitSize, mode);
if (!fpOnly) benchEc(bitSize, mode);
if (misc) {
benchToStr16();
benchFromStr16();
} else {
if (!ecOnly) benchFp(bitSize, mode);
if (!fpOnly) benchEc(bitSize, mode);
}
} catch (std::exception& e) {
printf("ERR %s\n", e.what());
}

@ -659,57 +659,3 @@ CYBOZU_TEST_AUTO(toStr16)
}
}
#if 0
CYBOZU_TEST_AUTO(toStr16bench)
{
const char *tbl[] = {
"0x0",
"0x5",
"0x123",
"0x123456789012345679adbc",
"0xffffffff26f2fc170f69466a74defd8d",
"0x100000000000000000000000000000033",
"0x11ee12312312940000000000000000000000000002342343"
};
const int C = 500000;
Fp::setModulo("0xffffffffffffffffffffffffffffffffffffffffffffff13");
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
std::string str, str2;
Fp x(tbl[i]);
CYBOZU_BENCH_C("Mont:getStr", C, x.getStr, str, 16);
mpz_class y(tbl[i]);
CYBOZU_BENCH_C("Gmp:getStr ", C, mcl::Gmp::getStr, str2, y, 16);
str2.insert(0, "0x");
CYBOZU_TEST_EQUAL(str, str2);
}
}
CYBOZU_TEST_AUTO(fromStr16bench)
{
const char *tbl[] = {
"0x0",
"0x5",
"0x123",
"0x123456789012345679adbc",
"0xffffffff26f2fc170f69466a74defd8d",
"0x100000000000000000000000000000033",
"0x11ee12312312940000000000000000000000000002342343"
};
const int C = 500000;
Fp::setModulo("0xffffffffffffffffffffffffffffffffffffffffffffff13");
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
std::string str = tbl[i];
Fp x;
CYBOZU_BENCH_C("Mont:setStr", C, x.setStr, str);
mpz_class y;
str.erase(0, 2);
CYBOZU_BENCH_C("Gmp:setStr ", C, mcl::Gmp::setStr, y, str, 16);
x.getStr(str, 16);
std::string str2;
mcl::Gmp::getStr(str2, y, 16);
str2.insert(0, "0x");
CYBOZU_TEST_EQUAL(str, str2);
}
}
#endif

Loading…
Cancel
Save