Last active
August 29, 2015 14:07
-
-
Save pupssman/49a037cb7788cc0a4ad4 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
(pytest)pupssman@dirigible:/trash$ for n in 1 2 4 8; do g++ -Dswapfunc=swap$n -O0 test.cpp && ./a.out; done | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 2541397 microsec for swap1 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 2391349 microsec for swap2 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 2280239 microsec for swap4 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 2297439 microsec for swap8 |
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
(pytest)pupssman@dirigible:/trash$ for n in 1 2 4 8; do g++ -Dswapfunc=swap$n -O1 test.cpp && ./a.out; done | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 770556 microsec for swap1 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 625807 microsec for swap2 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 537648 microsec for swap4 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 551631 microsec for swap8 |
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
(pytest)pupssman@dirigible:/trash$ for n in 1 2 4 8; do g++ -Dswapfunc=swap$n -O2 test.cpp && ./a.out; done | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 775289 microsec for swap1 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 532047 microsec for swap2 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 522245 microsec for swap4 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 587368 microsec for swap8 |
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
(pytest)pupssman@dirigible:/trash$ for n in 1 2 4 8; do g++ -Dswapfunc=swap$n -O3 test.cpp && ./a.out; done | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 281666 microsec for swap1 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 281743 microsec for swap2 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 282381 microsec for swap4 | |
Max size is18446744073709551615, will use 1073741824 bytes for test | |
Took 536043 microsec for swap8 |
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
(pytest)pupssman@dirigible:/trash$ dpkg -l | grep gcc | |
ii gcc 4:4.8.2-1ubuntu6 amd64 GNU C compiler | |
ii gcc-4.7 4.7.3-12ubuntu1 amd64 GNU C compiler | |
ii gcc-4.7-base:amd64 4.7.3-12ubuntu1 amd64 GCC, the GNU Compiler Collection (base package) | |
ii gcc-4.8 4.8.2-19ubuntu1 amd64 GNU C compiler | |
ii gcc-4.8-base:amd64 4.8.2-19ubuntu1 amd64 GCC, the GNU Compiler Collection (base package) | |
ii gcc-4.8-base:i386 4.8.2-19ubuntu1 i386 GCC, the GNU Compiler Collection (base package) | |
ii gcc-4.9-base:amd64 4.9-20140406-0ubuntu1 amd64 GCC, the GNU Compiler Collection (base package) | |
ii gcc-4.9-base:i386 4.9-20140406-0ubuntu1 i386 GCC, the GNU Compiler Collection (base package) | |
ii libgcc-4.7-dev:amd64 4.7.3-12ubuntu1 amd64 GCC support library (development files) | |
ii libgcc-4.8-dev:amd64 4.8.2-19ubuntu1 amd64 GCC support library (development files) | |
ii libgcc1:amd64 1:4.9-20140406-0ubuntu1 amd64 GCC support library | |
ii libgcc1:i386 1:4.9-20140406-0ubuntu1 i386 GCC support library | |
(pytest)pupssman@dirigible:/trash$ uname -a | |
Linux dirigible 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux | |
(pytest)pupssman@dirigible:/trash$ |
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
#define __STDC_LIMIT_MACROS | |
#include <iostream> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <ctime> | |
#ifndef swapfunc | |
#define swapfunc swap1 | |
#endif | |
#define STRINGY(X) #X | |
#define STRINGYMACRO(X) STRINGY(X) | |
using namespace std; | |
void fill(char* start, size_t len) { | |
for (int i = 0; i < len; i ++) { | |
*(start + i) = 'A'; | |
} | |
} | |
void swap1(char* src, char* dst, size_t len) {for(size_t i = 0; i < len; i += 1) {*dst++ = *src++;}} | |
void swap2(char* src, char* dst, size_t len) {for(size_t i = 0; i < len; i += 2) {*dst++ = *src++; *dst++ = *src++;}} | |
void swap4(char* src, char* dst, size_t len) {for(size_t i = 0; i < len; i += 4) {*dst++ = *src++; *dst++ = *src++; *dst++ = *src++; *dst++ = *src++;}} | |
void swap8(char* src, char* dst, size_t len) {for(size_t i = 0; i < len; i += 8) {*dst++ = *src++; *dst++ = *src++; *dst++ = *src++; *dst++ = *src++; *dst++ = *src++; *dst++ = *src++; *dst++ = *src++; *dst++ = *src++;}} | |
int main() { | |
size_t len = 1024 * 1024 * 1024; | |
cout << "Max size is" << SIZE_MAX << ", will use "<< len << " bytes for test" << endl; | |
char* src = (char*) malloc(len); | |
char* dst = (char*) malloc(len); | |
fill(src, len); | |
clock_t start = clock(); | |
swapfunc(src, dst, len); | |
clock_t end = clock(); | |
cout << "Took " << (unsigned int)(end - start) << " microsec for "<< STRINGYMACRO(swapfunc) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment