Add BPF benchmarks
This commit is contained in:
27
programs/bpf/c/src/bench_alu.c
Normal file
27
programs/bpf/c/src/bench_alu.c
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @brief Benchmark program that does work
|
||||
*
|
||||
* Counts Armstrong Numbers between 1 and x
|
||||
*/
|
||||
|
||||
#include <solana_sdk.h>
|
||||
|
||||
extern bool entrypoint(const uint8_t *input) {
|
||||
uint64_t x = *(uint64_t *)input;
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
Reference in New Issue
Block a user