Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bddicken committed Dec 9, 2024
1 parent 0ff4752 commit 4921d3b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ You are also welcome to add new top-level benchmarks dirs

Each benchmark exists in a subdirectory with the corresponding name.

## loops
## [loops](./loops/README.md)

A simple, not-super-useful program that does a total of 1 billion loop iterations, with some addition and mod operations for each.
The idea with this is to emphasizes loop, conditional, and basic math performance.

## fibonacci

Expand Down
28 changes: 28 additions & 0 deletions loops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Loops

A simple, not-super-useful program that does a total of 1 billion loop iterations, with some addition and mod operations for each.
The idea with this is to emphasize loop, conditional, and basic math performance.

Below is the reference C program.
All languages must do the same array work and computations outlined here.

```C
#include "stdio.h"
#include "stdlib.h"
#include "stdint.h"
#include "time.h"

int main (int argc, char** argv) { // EVERY PROGRAM IN THIS BENCHMARK MUST...
int u = atoi(argv[1]); // Get an single input number from the command line
srand(time(NULL));
int r = rand() % 10000; // Get a single random integer 0 <= r < 10k
int32_t a[10000] = {0}; // Create an array of 10k elements initialized to 0
for (int i = 0; i < 10000; i++) { // 10k outer loop iterations with an iteration variable
for (int j = 0; j < 100000; j++) { // 100k inner loop iterations, per outer loop iteration, with iteration variable
a[i] = a[i] + j%u; // For all 1B iterations, must access array element, compute j%u, update array location
}
a[i] += r; // For all 10k outer iterations, add the random value to each element in array
}
printf("%d\n", a[r]); // Print out a single element from the array
}
```

0 comments on commit 4921d3b

Please sign in to comment.