-
-
Save ykm11/7d8b48d628c281ebe21004572f2c41e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "func.hpp" | |
#include <iostream> | |
#include <string.h> | |
#include <gmpxx.h> | |
void fff(mp_limb_t *x) { | |
memset(x, 0, sizeof(mp_limb_t)*4); | |
} | |
void fff(mp_limb_t *x, size_t n) { | |
memset(x, 0, sizeof(mp_limb_t)*n); | |
} | |
void ggg(mp_limb_t *x) { | |
mpn_zero(x, 4); | |
} | |
void ggg(mp_limb_t *x, size_t n) { | |
mpn_zero(x, n); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <gmpxx.h> | |
void fff(mp_limb_t*); | |
void fff(mp_limb_t*, size_t); | |
void ggg(mp_limb_t*); | |
void ggg(mp_limb_t*, size_t); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "func.hpp" | |
#include <iostream> | |
#include <time.h> | |
#include <gmpxx.h> | |
int main() { | |
const int N = 10000000; | |
time_t begin, end; | |
mp_limb_t x[4]; | |
begin = clock(); | |
for (size_t i = 0; i < N; i++) { | |
fff(x, 4); | |
} | |
end = clock(); | |
printf("memset(x, 4):\t%f [nsec]\n", double(end-begin)*1e9/N/CLOCKS_PER_SEC); | |
begin = clock(); | |
for (size_t i = 0; i < N; i++) { | |
ggg(x, 4); | |
} | |
end = clock(); | |
printf("mpn_zero(x, 4):\t%f [nsec]\n\n", double(end-begin)*1e9/N/CLOCKS_PER_SEC); | |
begin = clock(); | |
for (size_t i = 0; i < N; i++) { | |
fff(x); | |
} | |
end = clock(); | |
printf("memset(x):\t%f [nsec]\n", double(end-begin)*1e9/N/CLOCKS_PER_SEC); | |
begin = clock(); | |
for (size_t i = 0; i < N; i++) { | |
ggg(x); | |
} | |
end = clock(); | |
printf("mpn_zero(x):\t%f [nsec]\n\n", double(end-begin)*1e9/N/CLOCKS_PER_SEC); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CXXFLAGS=-O3 -Wall -Wextra | |
LDFLAGS=-lgmpxx -lgmp | |
all: main | |
%.o: %.cpp | |
$(CXX) $< $(CXXFLAGS) -c | |
main: main.o func.o | |
$(CXX) main.o func.o $(CXXFLAGS) $(LDFLAGS) | |
.PHONY: | |
clean | |
clean: | |
$(RM) *.o a.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## CPUINFO | |
model name : AMD Ryzen 7 3700X 8-Core Processor | |
cpu MHz : 3600.000 | |
/* movups命令が利用可能 */ | |
$ make && repeat 20 ./a.out | |
... | |
memset(x, 4): 2.116500 [nsec] | |
mpn_zero(x, 4): 2.592400 [nsec] | |
memset(x): 1.173900 [nsec] | |
mpn_zero(x): 2.616200 [nsec] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment