-
-
Save dongjinahn/9544d96c2c14690deedfc0e35a0e7847 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
long a = 1; | |
long b = 2; | |
long c = a + b; | |
char x = 1; | |
char y = 2; | |
char z = x + y; |
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
template <class T> | |
T sum(T* arr, int n) { | |
T sum = 0; | |
for (in i = 0; i < n; ++i) { | |
sum += arr[i]; | |
} | |
return sum; | |
} | |
template <class T> | |
T* generate_zerosum_array(int n) { | |
if (n % 2 != 0) throw "n must be even!"; | |
T* arr = new T[n](); | |
for (int i = 0; i < n; i += 2) { | |
arr[i] = static_cast<T>(rand() % SHRT_MAX); | |
arr[i + 1] = -arr[i]; | |
} | |
return arr; | |
} | |
template <class T> | |
void benchmark(string name, int arr_len) { | |
auto begin = clock(); | |
cout << "Start generation" << endl; | |
auto arr = generate_zerosum_array<T>(arr_len); | |
auto end = clock(); | |
auto elapsed = double(end - begin) / CLOCKS_PER_SEC; | |
cout << "End generation, elapsed " << fixed << elpased << endl; | |
begin = clock(); | |
auto res = sum<T>(arr, arr_len); | |
end = clock(); | |
elapsed = double(end - begin) / CLOCKS_PER_SEC; | |
cout << name << " sum: " << res << ", elapsed " << fixed << elapsed << endl; | |
delete[] arr; | |
} | |
int main(int argc, char** argc) { | |
srand((unsigned int) time(0)); | |
cout.unsetf(ios::floatfield); | |
cout.precision(20); | |
int arr_len = atoi(argv[1]); | |
benchmark<int8_t>("int8_t", arr_len); | |
benchmark<int16_t>("int16_t", arr_len); | |
benchmark<int32_t>("int32_t", arr_len); | |
benchmark<int64_t>("int64_t", arr_len); | |
return 0; | |
} |
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
x = y + 1; | |
z1 = x + k1; | |
if (z == 0) a = 0; | |
else a = 1; | |
x = a + 1; | |
z2 = x + k2 |
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
if (foo) v = 1; | |
else v = 2; | |
x = v + 1; |
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
if (foo) v1 = 1; | |
else v2 = 2; | |
x = v? + 1; |
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
if (foo) v1 = 1; | |
else v2 = 2; | |
v3 = phi(v1, v2); | |
x = v3 + 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment