-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from codrutiftode/libseff-first-benchmarks
Add Libseff Benchmarks
- Loading branch information
Showing
14 changed files
with
832 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: libseff | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the main branch | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
#From https://docs.github.com/en/actions/guides/publishing-docker-images | ||
jobs: | ||
bench-system-libseff: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- uses: satackey/action-docker-layer-caching@v0.0.11 | ||
# Ignore the failure of a step and avoid terminating the job. | ||
continue-on-error: true | ||
|
||
- name: Add write permission to directories | ||
run: | | ||
find . -type d -exec chmod 777 {} \; | ||
- name: Test libseff system | ||
run: | | ||
make test_libseff | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
LIBSEFF := /home/ubuntu/libseff | ||
LIBSEFF_H := $(LIBSEFF)/src | ||
LIBSEFF_LIB := $(LIBSEFF)/output/lib | ||
|
||
CC := clang-14 | ||
CC_COMPILE_FLAGS := -std=gnu99 -O3 -I$(LIBSEFF_H) -fsplit-stack | ||
CC_WARN_FLAGS := -Wall -Wextra \ | ||
-Wformat=2 -Wno-unused-parameter -Wshadow \ | ||
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition \ | ||
-Wredundant-decls -Wnested-externs -Wmissing-include-dirs | ||
CC_LINK_FLAGS := -std=gnu99 -O3 | ||
|
||
LD := $(shell which ld.gold) | ||
LD_FLAGS := -fuse-ld=$(LD) -l:libseff.a -l:libutils.a -L$(LIBSEFF_LIB) | ||
|
||
compile_cmd = $(CC) $(CC_COMPILE_FLAGS) $(CC_WARN_FLAGS) -o main.o -c main.c | ||
link_cmd = $(CC) $(CC_LINK_FLAGS) -o main main.o $(LD_FLAGS) | ||
build_cmd = cd $(1) ; $(call compile_cmd, $(1)); $(call link_cmd, $(1)) | ||
test_cmd = cd $(1) ; ./main $(2) > actual ; echo $(3) > expected ; diff expected actual | ||
|
||
bench: build | ||
hyperfine --export-csv results.csv \ | ||
'./countdown/main 200000000' \ | ||
'./fibonacci_recursive/main 42' \ | ||
'./product_early/main 100000' \ | ||
'./iterator/main 40000000' \ | ||
'./generator/main 25' \ | ||
'./parsing_dollars/main 20000' \ | ||
'./resume_nontail/main 20000' \ | ||
'./handler_sieve/main 60000' | ||
|
||
test: build | ||
$(call test_cmd, countdown, 5, 0) | ||
$(call test_cmd, fibonacci_recursive, 5, 5) | ||
$(call test_cmd, product_early, 5, 0) | ||
$(call test_cmd, iterator, 5, 15) | ||
$(call test_cmd, generator, 5, 57) | ||
$(call test_cmd, parsing_dollars, 10, 55) | ||
$(call test_cmd, resume_nontail, 5, 37) | ||
$(call test_cmd, handler_sieve, 10, 17) | ||
|
||
build: | ||
$(call build_cmd, countdown) | ||
$(call build_cmd, fibonacci_recursive) | ||
$(call build_cmd, product_early) | ||
$(call build_cmd, iterator) | ||
$(call build_cmd, generator) | ||
$(call build_cmd, parsing_dollars) | ||
$(call build_cmd, resume_nontail) | ||
$(call build_cmd, handler_sieve) | ||
|
||
clean: | ||
-rm */main | ||
-rm */expected | ||
-rm */actual | ||
-rm */*.o | ||
-rm */*.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "seff.h" | ||
#include <stdio.h> | ||
|
||
DEFINE_EFFECT(get, 0, int64_t, {}); | ||
DEFINE_EFFECT(put, 1, void, { int64_t new_value; }); | ||
|
||
static int64_t evalState(seff_coroutine_t *k, int64_t initialState) { | ||
int64_t state = initialState; | ||
effect_set handles_state = HANDLES(get) | HANDLES(put); | ||
seff_request_t req = seff_handle(k, NULL, handles_state); | ||
|
||
int64_t result = -1; | ||
bool done = false; | ||
while (!done) { | ||
switch (req.effect) { | ||
CASE_EFFECT(req, get, { | ||
req = seff_handle(k, (void*) state, handles_state); | ||
break; | ||
}) | ||
CASE_EFFECT(req, put, { | ||
state = payload.new_value; | ||
req = seff_handle(k, 0, handles_state); | ||
break; | ||
}) | ||
CASE_RETURN(req, { | ||
result = (int64_t) payload.result; | ||
done = true; | ||
break; | ||
}) | ||
}; | ||
} | ||
return result; | ||
} | ||
|
||
static void* countdown(void* parameter) { | ||
int64_t state = PERFORM (get); | ||
while (state > 0) { | ||
PERFORM (put, state - 1); | ||
state = PERFORM (get); | ||
} | ||
return (void*) state; | ||
} | ||
|
||
static int64_t run(int64_t n) { | ||
seff_coroutine_t *k = seff_coroutine_new(countdown, (void*) n); | ||
int64_t result = evalState(k, n); | ||
seff_coroutine_delete(k); | ||
return result; | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
int64_t n = argc != 2 ? 5 : atoi(argv[1]); | ||
int64_t result = run(n); | ||
|
||
// Increase output buffer size to increase performance | ||
char buffer[8192]; | ||
setvbuf(stdout, buffer, _IOFBF, sizeof(buffer)); | ||
printf("%ld\n", result); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "seff.h" | ||
#include <stdio.h> | ||
|
||
DEFINE_EFFECT(get, 0, int64_t, {}); | ||
DEFINE_EFFECT(put, 1, void, { int64_t new_value; }); | ||
|
||
int64_t* evalState(seff_coroutine_t *k, int64_t param, int64_t *state) { | ||
seff_request_t req = seff_handle(k, (void*) param, HANDLES(get) | HANDLES(put)); | ||
switch (req.effect) { | ||
CASE_EFFECT(req, get, { | ||
return evalState(k, *state, state); | ||
}) | ||
CASE_EFFECT(req, put, { | ||
*state = payload.new_value; | ||
printf("New value: %ld\n", *state); | ||
return evalState(k, 0, state); | ||
}) | ||
CASE_RETURN(req, { | ||
return (int64_t*) payload.result; | ||
}) | ||
}; | ||
} | ||
|
||
void* countdown(void* parameter) { | ||
int64_t state = PERFORM (get); | ||
while (state > 0) { | ||
PERFORM (put, state - 1); | ||
state = PERFORM (get); | ||
} | ||
return &state; | ||
} | ||
|
||
int64_t run(int64_t n) { | ||
int64_t state = n; | ||
seff_coroutine_t *k = seff_coroutine_new(countdown, &state); | ||
return *evalState(k, 0, &state); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
int64_t n = argc != 2 ? 5 : atoi(argv[1]); | ||
int64_t result = run(n); | ||
printf("%ld\n", result); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "seff.h" | ||
#include <stdio.h> | ||
|
||
int64_t fib(int n) { | ||
if (n == 0) return 0; | ||
if (n == 1) return 1; | ||
return fib(n - 1) + fib(n - 2); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
int64_t n = argc != 2 ? 5 : atoi(argv[1]); | ||
int64_t result = fib(n); | ||
|
||
// Increase output buffer size to increase performance | ||
char buffer[8192]; | ||
setvbuf(stdout, buffer, _IOFBF, sizeof(buffer)); | ||
printf("%ld\n", result); | ||
return 0; | ||
} | ||
|
||
|
Oops, something went wrong.