diff --git a/CMakeLists.txt b/CMakeLists.txt index 497c429a9..1f953968d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.0) project(fastfetch) +option(BUILD_TESTS "Build test programs" OFF) + execute_process( COMMAND git rev-list --count HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" @@ -17,7 +19,9 @@ execute_process( set(PROJECT_VERSION "r${GIT_REV_LIST}.${GIT_REV_PARSE}") -# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -march=native -O3 -pipe -fno-plt") # for testing +if(BUILD_TESTS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -march=native -O3 -pipe -fno-plt") +endif(BUILD_TESTS) configure_file(src/fastfetch_config.h.in fastfetch_config.h) @@ -76,4 +80,15 @@ target_compile_definitions(flashfetch PUBLIC target_link_libraries(flashfetch ${CMAKE_DL_LIBS} -) \ No newline at end of file +) + +if(BUILD_TESTS) + add_executable(fastfetch-test-performance + tests/performance.c + ${SRCS} + ) + + target_link_libraries(fastfetch-test-performance + ${CMAKE_DL_LIBS} + ) +endif(BUILD_TESTS) diff --git a/tests/performance.c b/tests/performance.c new file mode 100644 index 000000000..a6dbf4e9c --- /dev/null +++ b/tests/performance.c @@ -0,0 +1,58 @@ +#include "fastfetch.h" + +#include + +#define FASTFETCH_TEST_PERFORMANCE(func) \ + { \ + struct timespec start, end; \ + clock_gettime(CLOCK_REALTIME, &start); \ + func; \ + clock_gettime(CLOCK_REALTIME, &end); \ + long nanos = end.tv_nsec - start.tv_nsec; \ + printf("\033[F"); \ + for(uint8_t i = 0; i < 110; i++) printf("\033[C"); \ + printf("%08ldns\n", nanos); \ + } \ + +int main(int argc, char** argv) +{ + FFinstance instance; + + FASTFETCH_TEST_PERFORMANCE( + puts("Initialization"); + ffInitState(&instance.state); + ffDefaultConfig(&instance.config); + ) + + FASTFETCH_TEST_PERFORMANCE( + puts("Configuration"); + ffLoadLogoSet(&instance.config, "arch"); + strcpy(instance.config.color, instance.config.logo.color); + ) + + FASTFETCH_TEST_PERFORMANCE(ffPrintTitle(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintSeperator(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintOS(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintHost(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintKernel(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintUptime(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintPackages(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintShell(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintResolution(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintDesktopEnvironment(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintWM(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintTheme(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintIcons(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintFont(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintTerminal(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintCPU(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintGPU(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintMemory(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintDisk(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintBattery(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintLocale(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintBreak(&instance)) + FASTFETCH_TEST_PERFORMANCE(ffPrintColors(&instance)) + + return 0; +} \ No newline at end of file diff --git a/tests/performance.sh b/tests/performance.sh new file mode 100755 index 000000000..365b01657 --- /dev/null +++ b/tests/performance.sh @@ -0,0 +1,6 @@ +rm -rf tests/build/ +mkdir -p tests/build/ +cd tests/build/ +cmake ../.. -DBUILD_TESTS=ON +cmake --build . --target fastfetch-test-performance +./fastfetch-test-performance "$@"