Skip to content

Commit

Permalink
add microbenchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
abolotina committed Oct 23, 2023
1 parent d4a8ad0 commit 92367fc
Show file tree
Hide file tree
Showing 17 changed files with 1,019 additions and 22 deletions.
49 changes: 49 additions & 0 deletions lion/branching10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// cksystemsgroup.github.io/unicorn
// @SOLUTIONS = 1
// @UNROLL = 100

uint64_t main() {
uint64_t a;
uint64_t b;
uint64_t c;
uint64_t *x;

x = malloc(8);
*x = 0;

a = 0;
b = 0;

c = read(0, x, 1);
a = *x;

if (a == 1) {
exit(0);
}
if (c == 0) {
exit(0);
}

a = a - 1;
a = a - 1;
a = a - 1;
a = a - 1;
a = a - 1;

c = read(0, x, 1);
b = *x;

if (b == 1) {
exit(0);
}
if (c == 0) {
exit(0);
}

a = a - 1;
a = a - 1;
a = a - 1;
a = a - 1;
a = a - 1;
exit(0);
}
50 changes: 50 additions & 0 deletions lion/branching11.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// cksystemsgroup.github.io/unicorn
// @SOLUTIONS = 1
// @UNROLL = 100

uint64_t main() {
uint64_t a;
uint64_t b;
uint64_t c;
uint64_t *x;

x = malloc(8);
*x = 0;

a = 0;
b = 0;

c = read(0, x, 2);
a = *x;

if (c == 0) {
exit(0);
}

a = a - 1;

if (a == 1) {
if (c == 1)
exit(0);
}

a = a - 1;

if (c == 1) {
exit(0);
}

a = a - 1;

b = (*x + 1);

if (b == 1) {
exit(0);
}
if (c == 0) {
exit(0);
}

a = a - 1;
exit(0);
}
36 changes: 36 additions & 0 deletions lion/branching12.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// cksystemsgroup.github.io/unicorn
// @SOLUTIONS = 1
// @UNROLL = 100

uint64_t main() {
uint64_t a;
uint64_t b;
uint64_t c;
uint64_t *x;

a = 1;

x = malloc(8);
*x = 0;

while (a <= 3) {
b = read(0, x, SIZEOFUINT8);

if (b == 0) {
return 0;
}

b = 0;
while (b < a * a) {
c = 0;
while (c < 20) {
c = c + 1;
}

b = b + 1;
}

a = a + 1;
}
return 0;
}
27 changes: 27 additions & 0 deletions lion/branching13.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// cksystemsgroup.github.io/unicorn
// @SOLUTIONS = 1
// @UNROLL = 100

uint64_t main() {
uint64_t b;
uint64_t c;
uint64_t d;
uint64_t *x;

d = 0;

x = malloc(8);
*x = 0;

b = read(0, x, SIZEOFUINT32);
d = *x;

c = b;
while (c > 0) {
c = c - 1;
}
if (d == 1)
exit(0);

return 0;
}
37 changes: 37 additions & 0 deletions lion/branching14.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// cksystemsgroup.github.io/unicorn
// @SOLUTIONS = 1
// @UNROLL = 100

uint64_t main() {
uint64_t a;
uint64_t b;
uint64_t c;
uint64_t d;
uint64_t *x;

d = 0;

x = malloc(8);
*x = 0;

b = read(0, x, SIZEOFUINT32);
d = *x;

c = b;
while (c > 0) {
c = c - 1;
}
if (d == 1)
exit(0);

a = 0;
while (a < b * b) {
c = 0;
while (c < 20) {
c = c + 1;
}
a = a + 1;
}

return 0;
}
20 changes: 20 additions & 0 deletions lion/branching15.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// cksystemsgroup.github.io/unicorn
// @SOLUTIONS = 1
// @UNROLL = 100

uint64_t main() {
uint64_t a;

a = VERIFIER_nondet_uchar();

if (a == 0)
exit(0);
else {
a = a - 1;
a = a - 1;
a = a - 1;
a = a - 1;
a = a - 1;
exit(0);
}
}
24 changes: 24 additions & 0 deletions lion/branching8.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// cksystemsgroup.github.io/unicorn
// @SOLUTIONS = 1
// @UNROLL = 100

uint64_t main() {
uint64_t a;
uint64_t b;
uint64_t *x;

a = 0;

x = malloc(8);
*x = 0;

while (a < 3) {
b = read(0, x, SIZEOFUINT8);

if (b == 0) {
return 0;
}
a = a + 1;
}
return 0;
}
35 changes: 35 additions & 0 deletions lion/branching9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// cksystemsgroup.github.io/unicorn
// @SOLUTIONS = 1
// @UNROLL = 100
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>

uint64_t main() {
uint64_t a;
uint64_t b;
uint64_t c;
uint64_t *x;

a = 0;

x = malloc(8);
*x = 0;

while (a < 3) {
b = read(0, x, 1);

c = *x;

if (c == 1) {
return 0;
}

if (b == 0) {
return 0;
}
a = a + 1;
}

return 0;
}
95 changes: 95 additions & 0 deletions lion/insertion-sort1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// cksystemsgroup.github.io/unicorn
// @SOLUTIONS = TODO
// @UNROLL = TODO

/*#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>*/

uint64_t found_position(uint64_t m, uint64_t* arr, uint64_t p, uint64_t to_swap) {
if (m > 0)
if (*(arr + p) > to_swap)
return 1;

return 0;
}

uint64_t main() {
uint64_t* arr;
uint64_t* buffer;
uint64_t size;

uint64_t to_swap;

uint64_t n;
uint64_t m;

uint64_t read_bytes;

size = 8;

arr = malloc(size * SIZEOFUINT64);
buffer = malloc(SIZEOFUINT64);

*buffer = 0;

// initialize array with user input
// printf("Insert initial values.\n");
n = 0;
while (n < size) {
read_bytes = read(0, buffer, SIZEOFUINT32);

if (read_bytes == 0)
size = n;
else
*(arr + n) = *buffer;

n = n + 1;
}

// debug
/*printf("Unsorted array: [ ");
n = 0;
while (n < size) {
printf("%ld ", *(arr + n));
n = n + 1;
}
printf("]\n");
fflush(stdout);*/

// sort array using insertion sort
// worst-case time complexity: O(n^2)
// best-case time complexity: O(n)
n = 1;
while (n < size) {
// next element to insert into correct slot
to_swap = *(arr + n);

// find correct slot
m = n;
while (found_position(m, arr, m - 1, to_swap)) {
*(arr + m) = *(arr + m - 1);

m = m - 1;
}

// swap next element into correct slot
*(arr + m) = to_swap;

n = n + 1;
}

// debug
/*printf("Sorted array: [ ");
n = 0;
while (n < size) {
printf("%ld ", *(arr + n));
n = n + 1;
}
printf("]\n");
fflush(stdout);
// gcc / valgrind
free(arr);*/
}
Loading

0 comments on commit 92367fc

Please sign in to comment.