miracl / MIRACL

MIRACL Cryptographic SDK: Multiprecision Integer and Rational Arithmetic Cryptographic Library is a C software library that is widely regarded by developers as the gold standard open source SDK for elliptic curve cryptography (ECC).
https://miracl.com
653 stars 242 forks source link

About the calculating speed of Big/big #70

Open MaxDumbledore opened 5 years ago

MaxDumbledore commented 5 years ago

I am new of using Miracl. It's a great and useful project. But I am now confused about the speed. With VS2017/64bit and Release Mode the program is much slower than the similar program written by Python language. For example, 10000000 times modulo operations, time occupied by program with Miracl is about 10 times longer than python. Hoping for advice.

mcarrickscott commented 5 years ago

I would need to see your code to express an opinion..

Mike

On Mon, Jan 21, 2019 at 4:13 PM MaxDumbledore notifications@github.com wrote:

I am new of using Miracl. It's a great and useful project. But I am now confused about the speed. With VS2017/64bit and Release Mode the program is much slower than the similar program written by Python language. For example, 10000000 times modulo operations, time occupied by program with Miracl is about 10 times longer than python. Hoping for advice.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/70, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jnDBAYfdG9KqbCL4raoCXHQD0Qjtks5vFecmgaJpZM4aLIQ1 .

MaxDumbledore commented 5 years ago

I would need to see your code to express an opinion.. Mike On Mon, Jan 21, 2019 at 4:13 PM MaxDumbledore @.***> wrote: I am new of using Miracl. It's a great and useful project. But I am now confused about the speed. With VS2017/64bit and Release Mode the program is much slower than the similar program written by Python language. For example, 10000000 times modulo operations, time occupied by program with Miracl is about 10 times longer than python. Hoping for advice. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#70>, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jnDBAYfdG9KqbCL4raoCXHQD0Qjtks5vFecmgaJpZM4aLIQ1 .

Thank you for watching my comment! Code is simple like `#include

include "big.h"

include

using namespace std; Miracl p(50, 10); Big a = "65465465465465465465132515"; Big b = "6546546546464646465468"; Big c = "365468468468468468468468468486"; Big d; int main() { long long af = clock(); for (int i = 1; i <= 10000000; i++) d=modmult(a,b,c); printf("%.2lf", (double)(clock()-af)/ CLOCKS_PER_SEC); return 0; }`

And in python import time a=65465465465465465465132515 b=6546546546464646465468 c=365468468468468468468468468486 d=0 af=time.time() for i in range(1,10000000): d=a*b%c print(time.time()-af)

The former with VS2017/Release takes 74. 69s in my computer, while the python version takes only 3.75s.

mcarrickscott commented 5 years ago

Well I compiled

include

include "big.h"

include

using namespace std;

Miracl p(50, 10);

Big a = (char )"65465465465465465465132515"; Big b = (char )"6546546546464646465468"; Big c = (char *)"365468468468468468468468468486"; Big d;

int main() { long long af = clock(); for (int i = 1; i <= 10000000; i++) d=modmult(a,b,c); printf("%.2lf \n", (double)(clock()-af)/ CLOCKS_PER_SEC); return 0; }

using

g++ -O2 maxd.cpp big.cpp miracl.a -o maxd

on my Ubuntu 18.04, and it ran in 6.09 seconds. By changing (50,10) to (50,0) it ran in 3.19 seconds. Your python code took 2.35 seconds.

Not much difference considering Python library code is written in highly optimized assembly language.

BTW those numbers aren't really very big, less than 100 bits!

Mike

On Mon, Jan 21, 2019 at 5:10 PM MaxDumbledore notifications@github.com wrote:

I would need to see your code to express an opinion.. Mike … <#m2061193188625218089> On Mon, Jan 21, 2019 at 4:13 PM MaxDumbledore @.***> wrote: I am new of using Miracl. It's a great and useful project. But I am now confused about the speed. With VS2017/64bit and Release Mode the program is much slower than the similar program written by Python language. For example, 10000000 times modulo operations, time occupied by program with Miracl is about 10 times longer than python. Hoping for advice. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#70 https://github.com/miracl/MIRACL/issues/70>, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jnDBAYfdG9KqbCL4raoCXHQD0Qjtks5vFecmgaJpZM4aLIQ1 .

Thank you for watching my comment! Code is simple like

include #include "big.h" #include using namespace std;

Miracl p(50, 10); Big a = "65465465465465465465132515"; Big b = "6546546546464646465468"; Big c = "365468468468468468468468468486"; Big d; int main() { long long af = clock(); for (int i = 1; i <= 10000000; i++) d=modmult(a,b,c); printf("%.2lf", (double)(clock()-af)/ CLOCKS_PER_SEC); return 0; }

And in python import time a=65465465465465465465132515 b=6546546546464646465468 c=365468468468468468468468468486 d=0 af=time.time() for i in range(1,10000000): d=a*b%c print(time.time()-af)

The former with VS2017/Release takes 74. 69s in my computer, while the python version takes only 3.75s.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/70#issuecomment-456143584, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jlUeH6d7sFLC7DMJGiFXW_BXxKoUks5vFfSCgaJpZM4aLIQ1 .

MaxDumbledore commented 5 years ago

Well I compiled #include #include "big.h" #include using namespace std; Miracl p(50, 10); Big a = (char )"65465465465465465465132515"; Big b = (char )"6546546546464646465468"; Big c = (char *)"365468468468468468468468468486"; Big d; int main() { long long af = clock(); for (int i = 1; i <= 10000000; i++) d=modmult(a,b,c); printf("%.2lf \n", (double)(clock()-af)/ CLOCKS_PER_SEC); return 0; } using g++ -O2 maxd.cpp big.cpp miracl.a -o maxd on my Ubuntu 18.04, and it ran in 6.09 seconds. By changing (50,10) to (50,0) it ran in 3.19 seconds. Your python code took 2.35 seconds. Not much difference considering Python library code is written in highly optimized assembly language. BTW those numbers aren't really very big, less than 100 bits! Mike On Mon, Jan 21, 2019 at 5:10 PM MaxDumbledore notifications@github.com wrote: I would need to see your code to express an opinion.. Mike … <#m2061193188625218089> On Mon, Jan 21, 2019 at 4:13 PM MaxDumbledore @.**> wrote: I am new of using Miracl. It's a great and useful project. But I am now confused about the speed. With VS2017/64bit and Release Mode the program is much slower than the similar program written by Python language. For example, 10000000 times modulo operations, time occupied by program with Miracl is about 10 times longer than python. Hoping for advice. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#70 <#70>>, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jnDBAYfdG9KqbCL4raoCXHQD0Qjtks5vFecmgaJpZM4aLIQ1 . Thank you for watching my comment! Code is simple like #include #include "big.h" #include using namespace std; Miracl p(50, 10); Big a = "65465465465465465465132515"; Big b = "6546546546464646465468"; Big c = "365468468468468468468468468486"; Big d; int main() { long long af = clock(); for (int i = 1; i <= 10000000; i++) d=modmult(a,b,c); printf("%.2lf", (double)(clock()-af)/ CLOCKS_PER_SEC); return 0; } And in python import time a=65465465465465465465132515 b=6546546546464646465468 c=365468468468468468468468468486 d=0 af=time.time() for i in range(1,10000000): d=ab%c print(time.time()-af) The former with VS2017/Release takes 74. 69s in my computer, while the python version takes only 3.75s. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#70 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jlUeH6d7sFLC7DMJGiFXW_BXxKoUks5vFfSCgaJpZM4aLIQ1 .

Thank you! And I found the reason why mine was so slow. It's all because I wrongly used Debug Mode to generate the miracl.lib file. After changing to Release Mode to generate the Library, it took about 25 seconds. By changing (50,10) to(50,0) it ran in 7.5 seconds.