Skip to content

Commit

Permalink
Merge pull request #58 from codrutiftode/libseff-first-benchmarks
Browse files Browse the repository at this point in the history
Add Libseff Benchmarks
  • Loading branch information
jasigal authored Jul 24, 2024
2 parents 6e4c3bf + 57516df commit b6a0583
Show file tree
Hide file tree
Showing 14 changed files with 832 additions and 13 deletions.
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/[email protected]
# 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 @@ -65,6 +65,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: system_base
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

0 comments on commit b6a0583

Please sign in to comment.