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

Fix linking error in CMake and divide by zero error in perf tests #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ include_directories(${PROJECT_SOURCE_DIR} "${PROJECT_SOURCE_DIR}/dns")
set_source_files_properties(dns/dns.c PROPERTIES COMPILE_FLAGS -std=c99)
add_library(dill ${sources})

find_package(Threads REQUIRED)
target_link_libraries(dill PUBLIC Threads::Threads)

# check and enable rt if available
list(APPEND CMAKE_REQUIRED_LIBRARIES rt)
check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
if(HAVE_CLOCK_GETTIME)
target_link_libraries(dill rt)
target_link_libraries(dill PUBLIC rt)
endif()

# Installation (https://github.com/forexample/package-example)
Expand Down Expand Up @@ -118,12 +121,12 @@ set(CMAKE_REQUIRED_DEFINITIONS )

check_function_exists(mprotect HAVE_MPROTECT)
if(HAVE_MPROTECT)
add_definitions(-DHAVE_MPROTECT)
target_compile_definitions(dill PUBLIC HAVE_MPROTECT)
endif()

check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
if(HAVE_POSIX_MEMALIGN)
add_definitions(-DHAVE_POSIX_MEMALIGN)
target_compile_definitions(dill PUBLIC HAVE_POSIX_MEMALIGN)
endif()

# tests
Expand Down
6 changes: 4 additions & 2 deletions perf/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ int main(int argc, char *argv[]) {
printf("done %ldM roundtrips in %f seconds\n",
(long)(count / 1000000), ((float)duration) / 1000);
printf("duration of passing a single message: %ld ns\n", ns);
printf("message passes per second: %fM\n",
(float)(1000000000 / ns) / 1000000);
if (ns > 0) {
printf("message passes per second: %fM\n",
(float)(1000000000 / ns) / 1000000);
}

return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion perf/choose.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ int main(int argc, char *argv[]) {
printf("done %ldM roundtrips in %f seconds\n",
(long)(count / 1000000), ((float)duration) / 1000);
printf("duration of passing a single message: %ld ns\n", ns);
printf("message passes per second: %fM\n",
if (ns > 0) {
printf("message passes per second: %fM\n",
(float)(1000000000 / ns) / 1000000);
}

return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion perf/ctxswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ int main(int argc, char *argv[]) {
printf("performed %ldM context switches in %f seconds\n",
(long)(count * 2 / 1000000), ((float)duration) / 1000);
printf("duration of one context switch: %ld ns\n", ns);
printf("context switches per second: %fM\n",
if (ns > 0) {
printf("context switches per second: %fM\n",
(float)(1000000000 / ns) / 1000000);
}

return 0;
}
Expand Down
6 changes: 4 additions & 2 deletions perf/go.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ int main(int argc, char *argv[]) {
printf("executed %ldM coroutines in %f seconds\n",
(long)(count / 1000000), ((float)duration) / 1000);
printf("duration of one coroutine creation+termination: %ld ns\n", ns);
printf("coroutine creations+terminations per second: %fM\n",
(float)(1000000000 / ns) / 1000000);
if (ns > 0) {
printf("coroutine creations+terminations per second: %fM\n",
(float)(1000000000 / ns) / 1000000);
}

return 0;
}
Expand Down
6 changes: 4 additions & 2 deletions perf/hdone.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ int main(int argc, char *argv[]) {
printf("done %ldM coroutine/channel cancellations in %f seconds\n",
(long)(count / 1000000), ((float)duration) / 1000);
printf("duration of coroutine/channel cancellation: %ld ns\n", ns);
printf("coroutine/channel cancellations per second: %fM\n",
(float)(1000000000 / ns) / 1000000);
if (ns > 0) {
printf("coroutine/channel cancellations per second: %fM\n",
(float)(1000000000 / ns) / 1000000);
}

return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion perf/whispers.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ int main(int argc, char *argv[]) {
printf("took %f seconds\n", (float)duration / 1000);
printf("performed %ld whispers in %f seconds\n", count, ((float)duration) / 1000);
printf("duration of one whisper: %ld ns\n", ns);
printf("whispers per second: %fM\n",
if (ns > 0) {
printf("whispers per second: %fM\n",
(float)(1000000000 / ns) / 1000000);
}

return 0;
}