Files
solana/programs/bpf/c/src/bench_alu/bench_alu.c

30 lines
589 B
C
Raw Normal View History

2018-11-14 12:06:06 -08:00
/**
* @brief Benchmark program that does work
*
* Counts Armstrong Numbers between 1 and x
*/
#include <solana_sdk.h>
extern uint64_t entrypoint(const uint8_t *input) {
2018-11-26 07:49:23 -08:00
uint64_t x = *(uint64_t *) input;
uint64_t *result = (uint64_t *) input + 1;
2018-11-14 12:06:06 -08:00
uint64_t count = 0;
for (int i = 1; i <= x; i++) {
uint64_t temp = i;
uint64_t num = 0;
while (temp != 0) {
uint64_t rem = (temp % 10);
num += rem * rem * rem;
temp /= 10;
}
if (i == num) {
count++;
}
}
2019-08-23 11:03:53 -07:00
// sol_log_64(x, count, 0, 0, 0);
2018-11-26 07:49:23 -08:00
*result = count;
return SUCCESS;
2018-11-14 12:06:06 -08:00
}