#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <gmp.h>
long long int div_mul(long long int x) {
return (x / 10) * 10;
}
long long int sub_mod(long long int x) {
return (x - x % 10);
}
int main() {
long long int testVal = INT64_MAX;
printf("%lld\n", div_mul
(testVal
)); printf("%lld\n", sub_mod
(testVal
));
const int limit = 1000000000;
const double checkPoint0
= (double) clock() / CLOCKS_PER_SEC
;
for (unsigned volatile i = 0; i < limit; ++i) {
long long int x = testVal;
long long int y = div_mul(x);
}
const double checkPoint1
= (double) clock() / CLOCKS_PER_SEC
; const double time_div_mul = checkPoint1 - checkPoint0;
printf("time with division followed by multiplication: %f\n", time_div_mul
);
const double checkPoint2
= (double) clock() / CLOCKS_PER_SEC
;
for (unsigned volatile i = 0; i < limit; ++i) {
long long int x = testVal;
long long int y = sub_mod(x);
}
const double checkPoint3
= (double) clock() / CLOCKS_PER_SEC
; const double time_sub_mod = checkPoint3 - checkPoint2;
printf("time with subtraction and modulo: %f\n", time_sub_mod
);
return 0;
}
I2luY2x1ZGUgPHN0ZGludC5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHRpbWUuaD4KI2luY2x1ZGUgPGdtcC5oPgoKbG9uZyBsb25nIGludCBkaXZfbXVsKGxvbmcgbG9uZyBpbnQgeCkgewogICAgcmV0dXJuICh4IC8gMTApICogMTA7Cn0KCmxvbmcgbG9uZyBpbnQgc3ViX21vZChsb25nIGxvbmcgaW50IHgpIHsKICAgIHJldHVybiAoeCAtIHggJSAxMCk7Cn0KCmludCBtYWluKCkgewogICAgCiAgICBsb25nIGxvbmcgaW50IHRlc3RWYWwgPSBJTlQ2NF9NQVg7CiAgICBwcmludGYoIiVsbGRcbiIsIGRpdl9tdWwodGVzdFZhbCkpOwogICAgcHJpbnRmKCIlbGxkXG4iLCBzdWJfbW9kKHRlc3RWYWwpKTsKICAgIAogICAgY29uc3QgaW50IGxpbWl0ID0gMTAwMDAwMDAwMDsKICAgIAogICAgY29uc3QgZG91YmxlI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