Skip to content

Commit 6148b2d

Browse files
committed
Updated benchmarks
1 parent 14cb23e commit 6148b2d

File tree

1 file changed

+28
-43
lines changed

1 file changed

+28
-43
lines changed

fuzz-tests/numerical/Polynomial.cpp

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -518,23 +518,23 @@ poly operator*(poly a, const num b) {
518518
}
519519
OP(*, *=) OP(+, +=) OP(-, -=);
520520
poly modK(poly a, int k) { return {a.begin(), a.begin() + min(k, sz(a))}; }
521-
poly inverse(poly A) {
522-
poly B = poly({num(1) / A[0]});
523-
while (sz(B) < sz(A)){
524-
poly C = B*modK(A, 2*sz(B));
525-
C = poly(C.begin()+sz(B), C.end());
526-
C = modK(B*C, sz(B));
527-
C.insert(C.begin(), sz(B), 0);
528-
B -= C;
529-
}
530-
return modK(B, sz(A));
531-
}
532521
// poly inverse(poly A) {
533522
// poly B = poly({num(1) / A[0]});
534-
// while (sz(B) < sz(A))
535-
// B = modK(B * (poly({num(2)}) - modK(A, 2*sz(B)) * B), 2 * sz(B));
523+
// while (sz(B) < sz(A)){
524+
// poly C = B*modK(A, 2*sz(B));
525+
// C = poly(C.begin()+sz(B), C.end());
526+
// C = modK(B*C, sz(B));
527+
// C.insert(C.begin(), sz(B), 0);
528+
// B -= C;
529+
// }
536530
// return modK(B, sz(A));
537531
// }
532+
poly inverse(poly A) {
533+
poly B = poly({num(1) / A[0]});
534+
while (sz(B) < sz(A))
535+
B = modK(B * (poly({num(2)}) - modK(A, 2*sz(B)) * B), 2 * sz(B));
536+
return modK(B, sz(A));
537+
}
538538
poly &operator/=(poly &a, poly b) {
539539
if (sz(a) < sz(b))
540540
return a = {};
@@ -651,12 +651,12 @@ bool checkEqual(mine::poly a, MIT::poly b) {
651651
for (int i = 0; i < ml; i++)
652652
if (a[i].x != b[i].v)
653653
return false;
654-
for (int i = ml; i < sz(a); i++)
655-
if (a[i].x != 0)
656-
return false;
657-
for (int i = ml; i < sz(b); i++)
658-
if (b[i].v != 0)
659-
return false;
654+
// for (int i = ml; i < sz(a); i++)
655+
// if (a[i].x != 0)
656+
// return false;
657+
// for (int i = ml; i < sz(b); i++)
658+
// if (b[i].v != 0)
659+
// return false;
660660
return true;
661661
}
662662

@@ -685,19 +685,17 @@ template <class A, class B> void testBinary(string name, A f1, B f2, int mxSz =
685685
assert(checkEqual(res, t));
686686
}
687687
cout << name << " tests passed!" << endl;
688+
auto a = genVec(mxSz);
689+
auto b = genVec(mxSz/2);
688690
{
689691
timeit x("mine");
690692
for (int it=0; it<NUMITERS; it++) {
691-
auto a = genVec((rand() % mxSz) + 1);
692-
auto b = genVec((rand() % mxSz) + 1);
693693
f1(a.first, b.first);
694694
}
695695
}
696696
{
697697
timeit x("MIT");
698698
for (int it=0; it<NUMITERS; it++) {
699-
auto a = genVec((rand() % mxSz) + 1);
700-
auto b = genVec((rand() % mxSz) + 1);
701699
f2(a.second, b.second);
702700
}
703701
}
@@ -713,17 +711,16 @@ template <class A, class B> void testUnary(string name, A f1, B f2, int mxSz = 5
713711
assert(checkEqual(res, t));
714712
}
715713
cout << name + " tests passed!" << endl;
714+
auto a = genVec(mxSz);
716715
{
717716
timeit x("mine");
718717
for (int it=0; it<NUMITERS; it++) {
719-
auto a = genVec((rand() % mxSz) + 1);
720718
f1(a.first);
721719
}
722720
}
723721
{
724722
timeit x("MIT");
725723
for (int it=0; it<NUMITERS; it++) {
726-
auto a = genVec((rand() % mxSz) + 1);
727724
f2(a.second);
728725
}
729726
}
@@ -745,25 +742,17 @@ template <class A, class B> void testPow(string name, A f1, B f2, int mxSz = 5,
745742
assert(checkEqual(res, t));
746743
}
747744
cout << name + " tests passed!" << endl;
745+
auto a = genVec((rand() % mxSz) + 1);
746+
int p = mxSz;
748747
{
749748
timeit x("mine");
750749
for (int it = 0; it < NUMITERS; it++) {
751-
auto a = genVec((rand() % mxSz) + 1);
752-
int pref = rand()%mxPref;
753-
for (int j=0; j<pref; j++)
754-
a.first.insert(a.first.begin(), mine::num(0));
755-
int p = rand() % mxSz;
756750
f1(a.first, p);
757751
}
758752
}
759753
{
760754
timeit x("mit");
761755
for (int it = 0; it < NUMITERS; it++) {
762-
auto a = genVec((rand() % mxSz) + 1);
763-
int pref = rand()%mxPref;
764-
for (int j=0; j<pref; j++)
765-
a.second.insert(a.second.begin(), MIT::num(0));
766-
int p = rand() % mxSz;
767756
f2(a.second, p);
768757
}
769758
}
@@ -780,19 +769,17 @@ template <class A, class B> void testEval(string name, A f1, B f2, int mxSz = 5)
780769
assert(checkEqual(res, t));
781770
}
782771
cout << name + " tests passed!" << endl;
772+
auto a = genVec(mxSz);
773+
auto b = genVec(mxSz);
783774
{
784775
timeit x("mine");
785776
for (int it = 0; it < NUMITERS; it++) {
786-
auto a = genVec((rand() % mxSz) + 1);
787-
auto b = genVec((rand() % mxSz)+1);
788777
f1(a.first, b.first);
789778
}
790779
}
791780
{
792781
timeit x("MIT");
793782
for (int it = 0; it < NUMITERS; it++) {
794-
auto a = genVec((rand() % mxSz) + 1);
795-
auto b = genVec((rand() % mxSz)+1);
796783
f2(a.second, b.second);
797784
}
798785
}
@@ -810,19 +797,17 @@ template <class A, class B> void testInterp(string name, A f1, B f2, int mxSz =
810797
assert(checkEqual(res, t));
811798
}
812799
cout << name + " tests passed!" << endl;
800+
auto a = genVec(mxSz);
801+
auto b = genVec(mxSz);
813802
{
814803
timeit x("mine");
815804
for (int it = 0; it < NUMITERS; it++) {
816-
auto a = genVec((rand() % mxSz) + 1);
817-
auto b = genVec((rand() % mxSz)+1);
818805
f1(a.first, b.first);
819806
}
820807
}
821808
{
822809
timeit x("MIT");
823810
for (int it = 0; it < NUMITERS; it++) {
824-
auto a = genVec((rand() % mxSz) + 1);
825-
auto b = genVec((rand() % mxSz)+1);
826811
f2(a.second, b.second);
827812
}
828813
}

0 commit comments

Comments
 (0)