Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Libseff Benchmarks #58

Merged
merged 31 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d374963
Add Dockerfile and Makefiles for libseff
codrutiftode May 21, 2024
09bd968
Add countdown, fibonacci and product_early
codrutiftode May 21, 2024
d078a7b
Add iterator
codrutiftode May 24, 2024
7ae9f02
Update Makefile error
codrutiftode May 24, 2024
db22609
Add generator
codrutiftode May 24, 2024
aed699e
Fix generator
codrutiftode May 24, 2024
036de05
Add resume_nontail, which fails when bench (segfault)
codrutiftode May 24, 2024
b197bdb
Fix resume_nontail
codrutiftode May 27, 2024
3fa837a
Ensure user programs compile with -fsplit-stack
codrutiftode May 27, 2024
69a2200
Make libseff build for release
codrutiftode May 27, 2024
ee0e35a
Add parsing_dollars bench
codrutiftode May 29, 2024
22d994f
Add handler_sieve bench
codrutiftode May 30, 2024
b5e24f5
Fix generator to be similar to other languages
codrutiftode May 30, 2024
64b70ad
Change recursion into for-loop in resume_nontail
codrutiftode May 30, 2024
3081a37
Explain output buffer performance trick
codrutiftode May 30, 2024
f4ee67a
Add the vbuffer trick to all tests
codrutiftode May 30, 2024
a5150c6
Add yml action file and update README
codrutiftode May 30, 2024
f2773ea
Fix top level Makefile
codrutiftode May 30, 2024
624f16b
Fix libseff in README
codrutiftode May 30, 2024
082b59f
Fix Makefile
codrutiftode Jun 4, 2024
4b07fd5
Make local functions static. Iterate forwards instead of backwards. A…
codrutiftode Jun 4, 2024
8c90e2f
Allow GNU extensions
codrutiftode Jun 4, 2024
eb7e29d
Update clang version
codrutiftode Jun 4, 2024
9a6fb93
Improve quality of generator
codrutiftode Jun 4, 2024
0cd16fd
Fix: leaking coroutine when handling catch
codrutiftode Jun 4, 2024
9dec3ed
Properly update clang to version 14
codrutiftode Jun 5, 2024
dc348bd
Make product_early use a linked list instead of array, and make it no…
codrutiftode Jun 5, 2024
2ae033f
Don't free memory in generator
codrutiftode Jun 11, 2024
65de3b4
Revert "Don't free memory in generator"
codrutiftode Jun 11, 2024
c58eb21
Pin compatible version of libseff in Dockerfile.
Jul 24, 2024
57516df
Added note for paring dollars about non-freed continuation.
jasigal Jul 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/system_libseff.yml
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

12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ test_libmpeff: system_libmpeff
docker run -v $(shell pwd):/source $(DOCKERHUB):libmpeff \
make -C /source/benchmarks/libmpeff test

# libseff
system_libseff:
docker build -t $(DOCKERHUB):libseff systems/libseff

bench_libseff: system_libseff
docker run -it --init -v $(shell pwd):/source $(DOCKERHUB):libseff \
make -C /source/benchmarks/libseff

test_libseff: system_libseff
docker run -v $(shell pwd):/source $(DOCKERHUB):libseff \
make -C /source/benchmarks/libseff test

# Links
system_links:
docker build -t $(DOCKERHUB):links systems/links
Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,26 @@ contains the results of running the Multicore OCaml benchmarks.
| [Koka](https://github.com/koka-lang/koka) | [![Koka](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_koka.yml/badge.svg)](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_koka.yml) |
| [libhandler](https://github.com/koka-lang/libhandler) | [![libhandler](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_libhandler.yml/badge.svg)](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_libhandler.yml) |
| [libmpeff](https://github.com/koka-lang/libmprompt) | [![libmpeff](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_libmpeff.yml/badge.svg)](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_libmpeff.yml) |
| [libseff](https://github.com/effect-handlers/libseff.git) | [![libseff](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_libseff.yml/badge.svg)](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_libseff.yml) |
| [Links](https://github.com/links-lang/links) | [![Links](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_links.yml/badge.svg)](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_links.yml) |
| [Multicore OCaml](https://github.com/ocaml-multicore/ocaml-multicore) | [![Multicore OCaml](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_ocaml.yml/badge.svg)](https://github.com/effect-handlers/effect-handlers-bench/actions/workflows/system_ocaml.yml) |


## Benchmark availability

| | Eff | Effekt | Handlers in Action | Koka | Multicore OCaml |
| :---------------------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
| **Countdown** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Fibonacci Recursive** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Product Early** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Iterator** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Nqueens** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Generator** | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Tree explore** | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
| **Triples** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Parsing Dollars** | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
| **Resume Nontail** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Handler Sieve** | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | :heavy_check_mark: |
| | Eff | Effekt | Handlers in Action | Koka | Multicore OCaml | Libseff |
| :---------------------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
| **Countdown** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Fibonacci Recursive** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Product Early** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Iterator** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Nqueens** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: |
| **Generator** | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Tree explore** | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: |
| **Triples** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: |
| **Parsing Dollars** | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Resume Nontail** | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| **Handler Sieve** | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |

Legend:

Expand Down
57 changes: 57 additions & 0 deletions benchmarks/libseff/Makefile
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
60 changes: 60 additions & 0 deletions benchmarks/libseff/countdown/main.c
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;
}
44 changes: 44 additions & 0 deletions benchmarks/libseff/countdown/main_rec.c
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;
}
21 changes: 21 additions & 0 deletions benchmarks/libseff/fibonacci_recursive/main.c
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;
}


Loading
Loading