aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2015-07-06 05:26:20 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2015-07-06 05:26:20 +0800
commit4da3ed04fc296856d1d7c2abc621fff86093dd03 (patch)
treeac4a48c8dbb37e022c83bfadc29ea32f794ac6ca
parent0a326d8a9cd79d6dfc9c8d5485fed6860b3ae47d (diff)
downloadtangerine-mcl-4da3ed04fc296856d1d7c2abc621fff86093dd03.tar.gz
tangerine-mcl-4da3ed04fc296856d1d7c2abc621fff86093dd03.tar.zst
tangerine-mcl-4da3ed04fc296856d1d7c2abc621fff86093dd03.zip
add bench
-rw-r--r--sample/Makefile4
-rw-r--r--sample/bench.cpp96
-rw-r--r--sample/ecdh.cpp (renamed from sample/ecdh_smpl.cpp)0
-rw-r--r--sample/random.cpp (renamed from sample/random_smpl.cpp)0
4 files changed, 98 insertions, 2 deletions
diff --git a/sample/Makefile b/sample/Makefile
index 96678a6..a5c41dd 100644
--- a/sample/Makefile
+++ b/sample/Makefile
@@ -7,8 +7,8 @@ SRC=$(wildcard *.cpp)
all: $(TARGET)
-test: $(TARGET)
- @$(SAMPLE_TEST)
+#test: $(TARGET)
+# @$(SAMPLE_TEST)
$(OBJDIR):
@$(MKDIR) $(OBJDIR)
diff --git a/sample/bench.cpp b/sample/bench.cpp
new file mode 100644
index 0000000..1f264ae
--- /dev/null
+++ b/sample/bench.cpp
@@ -0,0 +1,96 @@
+#include <cybozu/benchmark.hpp>
+#include <cybozu/option.hpp>
+#include <mcl/fp.hpp>
+
+typedef mcl::FpT<> Fp;
+
+void benchFpSub(const char *pStr, const char *xStr, const char *yStr, mcl::fp::Mode mode)
+{
+ Fp::setModulo(pStr, 0, mode);
+ Fp x(xStr);
+ Fp y(yStr);
+
+ double addT, subT, mulT, invT;
+ CYBOZU_BENCH_T(addT, Fp::add, x, x, x);
+ CYBOZU_BENCH_T(subT, Fp::sub, x, x, y);
+ CYBOZU_BENCH_T(mulT, Fp::mul, x, x, x);
+ CYBOZU_BENCH_T(invT, x += y;Fp::inv, x, x); // avoid same jmp
+ printf("bit % 3d add %8.2f sub %8.2f mul %8.2f inv %8.2f\n", (int)Fp::getBitSize(), addT, subT, mulT, invT);
+}
+
+void benchFp(size_t bitSize, int imode)
+{
+ const struct {
+ size_t bitSize;
+ const char *p;
+ const char *x;
+ const char *y;
+ } tbl[] = {
+ {
+ 192,
+ "0xfffffffffffffffffffffffe26f2fc170f69466a74defd8d",
+ "0x148094810948190412345678901234567900342423332197",
+ "0x7fffffffffffffffffffffe26f2fc170f69466a74defd8d",
+ },
+ {
+ 256,
+ "0x2523648240000001ba344d80000000086121000000000013a700000000000013",
+ "0x1480948109481904123456789234234242423424201234567900342423332197",
+ "0x151342342342341517fffffffffffffffffffffe26f2fc170f69466a74defd8d",
+ },
+ {
+ 384,
+ "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff",
+ "0x19481084109481094820948209482094820984290482212345678901234567900342308472047204720422423332197",
+ "0x209348209481094820984209842094820948204204243123456789012345679003423084720472047204224233321972",
+
+ },
+ {
+ 521,
+ "0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
+ "0x2908209582095820941098410948109482094820984209840294829049240294242498540975555312345678901234567900342308472047204720422423332197",
+ "0x3948384209834029834092384204920349820948205872380573205782385729385729385723985837ffffffffffffffffffffffe26f2fc170f69466a74defd8d",
+
+ },
+ };
+ for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
+ if (bitSize != 0 && tbl[i].bitSize != bitSize) continue;
+ benchFpSub(tbl[i].p, tbl[i].x, tbl[i].y, mcl::fp::FP_AUTO);
+ benchFpSub(tbl[i].p, tbl[i].x, tbl[i].y, mcl::fp::FP_LLVM);
+ benchFpSub(tbl[i].p, tbl[i].x, tbl[i].y, mcl::fp::FP_LLVM_MONT);
+ benchFpSub(tbl[i].p, tbl[i].x, tbl[i].y, mcl::fp::FP_XBYAK);
+ }
+}
+
+void benchEc(size_t, int)
+{
+}
+
+int main(int argc, char *argv[])
+ try
+{
+ size_t bitSize;
+ int mode;
+ bool ecOnly;
+ bool fpOnly;
+ cybozu::Option opt;
+ opt.appendOpt(&bitSize, 0, "b", ": bitSize");
+ opt.appendOpt(&mode, 0, "m", ": mode(0:auto, 1:llvm, 2:llvm+mont, 3:xbyak");
+ opt.appendBoolOpt(&ecOnly, "ec", ": ec only");
+ opt.appendBoolOpt(&fpOnly, "fp", ": fp only");
+ opt.appendHelp("h", ": show this message");
+ if (!opt.parse(argc, argv)) {
+ opt.usage();
+ exit(1);
+ }
+ if (mode < 0 || mode > 3) {
+ printf("bad mode %d\n", mode);
+ opt.usage();
+ exit(1);
+ }
+ if (!ecOnly) benchFp(bitSize, mode);
+ if (!fpOnly) benchEc(bitSize, mode);
+} catch (std::exception& e) {
+ printf("ERR %s\n", e.what());
+}
+
diff --git a/sample/ecdh_smpl.cpp b/sample/ecdh.cpp
index 22b9734..22b9734 100644
--- a/sample/ecdh_smpl.cpp
+++ b/sample/ecdh.cpp
diff --git a/sample/random_smpl.cpp b/sample/random.cpp
index 9c15552..9c15552 100644
--- a/sample/random_smpl.cpp
+++ b/sample/random.cpp