performance tests

This commit is contained in:
Linus Dierheimer
2021-03-07 20:05:00 +01:00
parent 43022c0129
commit 6cc99423c9
3 changed files with 81 additions and 2 deletions
+17 -2
View File
@@ -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}
)
)
if(BUILD_TESTS)
add_executable(fastfetch-test-performance
tests/performance.c
${SRCS}
)
target_link_libraries(fastfetch-test-performance
${CMAKE_DL_LIBS}
)
endif(BUILD_TESTS)
+58
View File
@@ -0,0 +1,58 @@
#include "fastfetch.h"
#include <time.h>
#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;
}
+6
View File
@@ -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 "$@"