diff --git a/Benchmark/libc_locale.cpp b/Benchmark/libc_locale.cpp index e12e57db0da4ad49f0dcedee1b907e9615ea6388..5a2afdeded6f07e01e21a8f7ac5b35f3fbf07ff8 100755 --- a/Benchmark/libc_locale.cpp +++ b/Benchmark/libc_locale.cpp @@ -16,6 +16,7 @@ #ifdef ONO_CURRENT_INTERFACE #include #include +#include #include "sys/types.h" #include "sys/epoll.h" #include "sys/stat.h" @@ -82,10 +83,25 @@ static void Bm_function_Setlocale_Time(benchmark::State &state) state.SetBytesProcessed(state.iterations()); } +static void Bm_function_Locale_nl_langinfo(benchmark::State &state) +{ + for (auto _ : state) { + benchmark::DoNotOptimize(nl_langinfo(CODESET)); + } +} +static void Bm_function_Locale_localeconv(benchmark::State &state) +{ + for (auto _ : state) { + benchmark::DoNotOptimize(localeconv()); + } +} + MUSL_BENCHMARK(Bm_function_Setlocale_All); MUSL_BENCHMARK(Bm_function_Setlocale_All1); MUSL_BENCHMARK(Bm_function_Setlocale_All2); MUSL_BENCHMARK(Bm_function_Setlocale_Collate); MUSL_BENCHMARK(Bm_function_Setlocale_Ctype); MUSL_BENCHMARK(Bm_function_Setlocale_Time); +MUSL_BENCHMARK(Bm_function_Locale_nl_langinfo); +MUSL_BENCHMARK(Bm_function_Locale_localeconv); #endif diff --git a/Benchmark/libc_mman.cpp b/Benchmark/libc_mman.cpp index abf44053e8d5f084eb40d36a58928f6c41bbedf1..1a033269b11860cf77f5acbf994e4caee1b1550b 100755 --- a/Benchmark/libc_mman.cpp +++ b/Benchmark/libc_mman.cpp @@ -134,9 +134,28 @@ static void Bm_function_Mmap_anonymous(benchmark::State &state) state.SetItemsProcessed(state.iterations()); } +static void Bm_function_Madvise(benchmark::State &state) +{ + int fd = open("/data/data/my_mmap_anonymous.txt", O_RDWR | O_CREAT); + if (fd == -1) { + perror("open anonymous mmap"); + exit(EXIT_FAILURE); + } + size_t length = state.range(0); + int *addr = (int*)mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); + for (auto _ : state) { + benchmark::DoNotOptimize(madvise(addr, length, 0)); + } + munmap(addr, length); + close(fd); + remove("/data/data/my_mmap_anonymous.txt"); + state.SetItemsProcessed(state.iterations()); +} + MUSL_BENCHMARK_WITH_ARG(Bm_function_Mmap_1, "MMAP_SIZE"); MUSL_BENCHMARK_WITH_ARG(Bm_function_Mmap_2, "MMAP_SIZE"); MUSL_BENCHMARK_WITH_ARG(Bm_function_Mmap_3, "MMAP_SIZE"); MUSL_BENCHMARK_WITH_ARG(Bm_function_Munmap, "MMAP_SIZE"); MUSL_BENCHMARK_WITH_ARG(Bm_function_Mmap_anonymous, "MMAP_SIZE"); +MUSL_BENCHMARK_WITH_ARG(Bm_function_Madvise, "MMAP_SIZE"); #endif \ No newline at end of file diff --git a/Benchmark/libc_network.cpp b/Benchmark/libc_network.cpp index a32baed4face19848554449c18a09ccf5686df72..24af1db6df99845678333c947e6892acdbfb682b 100755 --- a/Benchmark/libc_network.cpp +++ b/Benchmark/libc_network.cpp @@ -54,6 +54,14 @@ static void Bm_function_Getaddrinfo_intranet1(benchmark::State &state) state.SetBytesProcessed(state.iterations()); } +static void Bm_function_Network_ntohs(benchmark::State &state) +{ + uint16_t srcPort = 5060; + for (auto _ : state) { + benchmark::DoNotOptimize(ntohs(srcPort)); + } +} MUSL_BENCHMARK(Bm_function_Getaddrinfo_external_network); MUSL_BENCHMARK(Bm_function_Getaddrinfo_intranet1); +MUSL_BENCHMARK(Bm_function_Network_ntohs); #endif \ No newline at end of file diff --git a/Benchmark/libc_pthread.cpp b/Benchmark/libc_pthread.cpp index 073989b5c399b832e1eb01cc7a284534d3bc3b8c..a4c47b9bc80ff88b7843e1373d54dd52d13e9cf9 100755 --- a/Benchmark/libc_pthread.cpp +++ b/Benchmark/libc_pthread.cpp @@ -15,12 +15,23 @@ #ifdef ONO_CURRENT_INTERFACE #include - #include "pthread.h" +#include "semaphore.h" +#include "signal.h" #include "threads.h" #include "unistd.h" #include "util.h" +static void Bm_function_pthread_mutexattr_settype(benchmark::State &state) +{ + pthread_mutexattr_t mutex_attr; + pthread_mutexattr_init(&mutex_attr); + while (state.KeepRunning()) { + benchmark::DoNotOptimize(pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_NORMAL)); + } + pthread_mutexattr_destroy(&mutex_attr); +} + static void Bm_function_pthread_mutex_trylock_fast(benchmark::State &state) { pthread_mutexattr_t mutex_attr; @@ -375,6 +386,58 @@ static void Bm_function_pthread_cond_broadcast(benchmark::State &state) state.SetBytesProcessed(state.iterations()); } +static void Bm_function_Sem_timewait(benchmark::State &state) +{ + sem_t semp; + sem_init(&semp, 0, 1); + struct timespec spec; + spec.tv_sec = 0; + spec.tv_nsec = 5; + while (state.KeepRunning()) { + sem_timedwait(&semp, &spec); + } + sem_destroy(&semp); +} + +static void Bm_function_Sem_post_wait(benchmark::State &state) +{ + sem_t semp; + sem_init(&semp, 0, 0); + struct timespec spec; + spec.tv_sec = 0; + spec.tv_nsec = 5; + while (state.KeepRunning()) { + sem_post(&semp); + sem_wait(&semp); + } + sem_destroy(&semp); +} + +static void Bm_function_pthread_cond_signal(benchmark::State &state) +{ + pthread_cond_t cond; + pthread_cond_init(&cond, NULL); + while (state.KeepRunning()) + { + pthread_cond_signal(&cond); + } + pthread_cond_destroy(&cond); + state.SetBytesProcessed(state.iterations()); +} + +static void Bm_function_Sigaddset(benchmark::State &state) +{ + sigset_t set; + sigemptyset(&set); + for (auto _ : state) { + benchmark::DoNotOptimize(sigaddset(&set, SIGUSR1)); + } + state.SetBytesProcessed(state.iterations()); +} + +MUSL_BENCHMARK(Bm_function_Sigaddset); +MUSL_BENCHMARK(Bm_function_pthread_cond_signal); +MUSL_BENCHMARK(Bm_function_pthread_mutexattr_settype); MUSL_BENCHMARK(Bm_function_pthread_mutex_trylock_fast); MUSL_BENCHMARK(Bm_function_pthread_mutex_trylock_errchk); MUSL_BENCHMARK(Bm_function_pthread_mutex_trylock_rec); @@ -396,4 +459,6 @@ MUSL_BENCHMARK(Bm_function_pthread_rwlock_timedrdlock); MUSL_BENCHMARK(Bm_function_pthread_rwlock_timedwrlock); MUSL_BENCHMARK(Bm_function_pthread_cond_timedwait); MUSL_BENCHMARK(Bm_function_pthread_cond_broadcast); +MUSL_BENCHMARK(Bm_function_Sem_timewait); +MUSL_BENCHMARK(Bm_function_Sem_post_wait); #endif \ No newline at end of file diff --git a/Benchmark/libc_stdio.cpp b/Benchmark/libc_stdio.cpp index 191e1cb7353806926d25c40faa749727f9caa249..837115d75140f745f2c13233a380e56097fd956d 100755 --- a/Benchmark/libc_stdio.cpp +++ b/Benchmark/libc_stdio.cpp @@ -1175,6 +1175,46 @@ static void Bm_function_Vfscanf_lluformat(benchmark::State &state) state.SetBytesProcessed(state.iterations()); } +static void Bm_function_Fileno_unlocked(benchmark::State &state) +{ + FILE *stream = fopen("/data/data/vfscanf_lluformat.txt", "w+"); + if (stream == nullptr) { + perror("fopen vfscanf lluformat"); + exit(EXIT_FAILURE); + } + for (auto _ : state) { + benchmark::DoNotOptimize(fileno_unlocked(stream)); + } + fclose(stream); + remove("/data/data/vfscanf_lluformat.txt"); + state.SetBytesProcessed(state.iterations()); +} + +static void Bm_function_Fseek_fflush(benchmark::State &state) +{ + FILE *f = fopen("/dev/zero", "r"); + if (f == nullptr) { + perror("fopen fseek set"); + exit(EXIT_FAILURE); + } + for (auto _ : state) { + benchmark::DoNotOptimize(fflush(f)); + } + fclose(f); + state.SetItemsProcessed(state.iterations()); +} + + +static void Bm_function_Sscanf_vsscanf_int(benchmark::State &state) +{ + for (auto _ : state) { + va_list ap; + benchmark::DoNotOptimize(vsscanf("20230515", "%04d%02d%02d", ap)); + } + state.SetBytesProcessed(state.iterations()); +} + + MUSL_BENCHMARK(Bm_function_Fopen_read); MUSL_BENCHMARK(Bm_function_Fopen_write); MUSL_BENCHMARK(Bm_function_Fopen_append); @@ -1247,4 +1287,7 @@ MUSL_BENCHMARK(Bm_function_Vfscanf_hhxformat); MUSL_BENCHMARK(Bm_function_Vfscanf_llxformat); MUSL_BENCHMARK(Bm_function_Vfscanf_lldformat); MUSL_BENCHMARK(Bm_function_Vfscanf_lluformat); +MUSL_BENCHMARK(Bm_function_Fileno_unlocked); +MUSL_BENCHMARK(Bm_function_Fseek_fflush); +MUSL_BENCHMARK(Bm_function_Sscanf_vsscanf_int); #endif \ No newline at end of file diff --git a/Benchmark/libc_stdlib.cpp b/Benchmark/libc_stdlib.cpp index 9c6e18ef73617da799a47d900c07c6e836308c3b..8c22c771fee666815fde1434f0f60e9d23cc8f70 100755 --- a/Benchmark/libc_stdlib.cpp +++ b/Benchmark/libc_stdlib.cpp @@ -48,6 +48,29 @@ static void Bm_function_Strtod(benchmark::State &state) } } +static void Bm_function_Strtof(benchmark::State &state) +{ + const char *var[] = {"+2.86500000e+01", "3.1415", "29", + "-123.456", "1.23e5", "0x1.2p3", + "-inf", "123foo"}; + const char *str = var[state.range(0)]; + char *ptr; + for (auto _ : state) { + benchmark::DoNotOptimize(strtof(str, &ptr)); + } +} + +static void Bm_function_Strtold(benchmark::State &state) +{ + const char *var[] = {"+2.86500000e+01", "3.1415", "29", + "-123.456", "1.23e5", "0x1.2p3", + "-inf", "123foo"}; + const char *str = var[state.range(0)]; + char *ptr; + for (auto _ : state) { + benchmark::DoNotOptimize(strtold(str, &ptr)); + } +} // Used to sort elements in an array static void Bm_function_Qsort(benchmark::State &state) { @@ -107,6 +130,8 @@ static void Bm_function_Realpath(benchmark::State &state) } MUSL_BENCHMARK_WITH_ARG(Bm_function_Strtod, "BENCHMARK_VARIABLE"); +MUSL_BENCHMARK_WITH_ARG(Bm_function_Strtof, "BENCHMARK_VARIABLE"); +MUSL_BENCHMARK_WITH_ARG(Bm_function_Strtold, "BENCHMARK_VARIABLE"); MUSL_BENCHMARK(Bm_function_Qsort); MUSL_BENCHMARK_WITH_ARG(Bm_function_Realpath, "REALPATH_VARIABLE"); #endif diff --git a/Benchmark/libc_string.cpp b/Benchmark/libc_string.cpp index 367c053cbe4e3e7d38b141f903171ee4dc6f972b..3e38d727de0a880e92cc3fa183b5c747ddf6aed3 100755 --- a/Benchmark/libc_string.cpp +++ b/Benchmark/libc_string.cpp @@ -258,6 +258,52 @@ static void Bm_function_Strcasecmp(benchmark::State &state) state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); } +static void Bm_function_Strncasecmp(benchmark::State &state) +{ + const size_t nbytes = state.range(0); + const size_t haystackAlignment = state.range(1); + const size_t needleAlignment = state.range(2); + + std::vector haystack; + std::vector needle; + char *haystackAligned = GetAlignedPtrFilled(&haystack, haystackAlignment, nbytes, 'x'); + char *needleAligned = GetAlignedPtrFilled(&needle, needleAlignment, nbytes, 'x'); + for (auto _ : state) { + benchmark::DoNotOptimize(strncasecmp(haystackAligned, needleAligned, nbytes)); + } + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); +} + +static void Bm_function_Strdup(benchmark::State &state) +{ + const size_t nbytes = state.range(0); + const size_t haystackAlignment = state.range(1); + std::vector haystack; + char *haystackAligned = GetAlignedPtrFilled(&haystack, haystackAlignment, nbytes, 'x'); + haystackAligned[nbytes - 1] = '\0'; + char* ptr = 0; + while (state.KeepRunning()) { + benchmark::DoNotOptimize(ptr = strdup(haystackAligned)); + free(ptr); + } + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); +} + +static void Bm_function_Strncat(benchmark::State &state) +{ + const size_t nbytes = state.range(0); + const size_t haystackAlignment = state.range(1); + std::vector haystack; + char *haystackAligned = GetAlignedPtrFilled(&haystack, haystackAlignment, nbytes, 'x'); + haystackAligned[nbytes - 1] = '\0'; + std::vector dstStack; + char *dst = GetAlignedPtrFilled(&dstStack, haystackAlignment, nbytes, '0'); + while (state.KeepRunning()) { + dst[0] = 0; + benchmark::DoNotOptimize(strncat(dst, haystackAligned, nbytes)); + } + state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes)); +} MUSL_BENCHMARK_WITH_ARG(Bm_function_Memchr, "STRING_LIMIT"); MUSL_BENCHMARK_WITH_ARG(Bm_function_Strnlen, "STRING_LIMIT"); MUSL_BENCHMARK_WITH_ARG(Bm_function_Stpncpy, "STRING_LIMIT"); @@ -270,6 +316,9 @@ MUSL_BENCHMARK(Bm_function_Strcasecmp_small_equal); MUSL_BENCHMARK(Bm_function_Strcasecmp_equal); MUSL_BENCHMARK(Bm_function_Strcasecmp_not_equal); MUSL_BENCHMARK_WITH_ARG(Bm_function_Strcasecmp, "ALIGNED_TWOBUF"); +MUSL_BENCHMARK_WITH_ARG(Bm_function_Strncasecmp, "ALIGNED_TWOBUF"); +MUSL_BENCHMARK_WITH_ARG(Bm_function_Strdup, "ALIGNED_ONEBUF"); +MUSL_BENCHMARK_WITH_ARG(Bm_function_Strncat, "ALIGNED_ONEBUF"); #ifdef ONO_CURRENT_INTERFACE MUSL_BENCHMARK(Bm_function_Strrchr); diff --git a/Benchmark/libc_time.cpp b/Benchmark/libc_time.cpp index 1afb24da04e91c3fda6f2db54b0f78001bea0589..0f4a14a476a783268344fbedea3f2a1de206cf04 100755 --- a/Benchmark/libc_time.cpp +++ b/Benchmark/libc_time.cpp @@ -55,9 +55,75 @@ static void Bm_function_Tzset(benchmark::State &state) tzset(); } } +static void Bm_function_Clock_nanosleep_realtime(benchmark::State &state) +{ + struct timespec req, rem; + req.tv_nsec = 10; + for (auto _ : state) { + benchmark::DoNotOptimize(clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem)); + } +} + +static void Bm_function_Clock_nanosleep_realtime_raw(benchmark::State &state) +{ + struct timespec req, rem; + req.tv_nsec = 10; + for (auto _ : state) { + benchmark::DoNotOptimize(clock_nanosleep(CLOCK_REALTIME_COARSE, 0, &req, &rem)); + } +} + +static void Bm_function_Clock_nanosleep_realtime_coarse(benchmark::State &state) +{ + struct timespec req, rem; + req.tv_nsec = 10; + for (auto _ : state) { + benchmark::DoNotOptimize(clock_nanosleep(CLOCK_REALTIME_COARSE, 0, &req, &rem)); + } +} + +static void Bm_function_Clock_nanosleep_monotonic(benchmark::State &state) +{ + struct timespec req, rem; + req.tv_nsec = 10; + for (auto _ : state) { + benchmark::DoNotOptimize(clock_nanosleep(CLOCK_MONOTONIC, 0, &req, &rem)); + } +} +static void Bm_function_Clock_nanosleep_monotonic_coarse(benchmark::State &state) +{ + struct timespec req, rem; + req.tv_nsec = 10; + for (auto _ : state) { + benchmark::DoNotOptimize(clock_nanosleep(CLOCK_MONOTONIC_COARSE, 0, &req, &rem)); + } +} +static void Bm_function_Clock_nanosleep_monotonic_raw(benchmark::State &state) +{ + struct timespec req, rem; + req.tv_nsec = 10; + for (auto _ : state) { + benchmark::DoNotOptimize(clock_nanosleep(CLOCK_MONOTONIC_RAW, 0, &req, &rem)); + } +} +static void Bm_function_Clock_nanosleep_boottime(benchmark::State &state) +{ + struct timespec req, rem; + req.tv_nsec = 10; + for (auto _ : state) { + benchmark::DoNotOptimize(clock_nanosleep(CLOCK_BOOTTIME, 0, &req, &rem)); + } +} MUSL_BENCHMARK(Bm_function_Nanosleep_0ns); MUSL_BENCHMARK(Bm_function_Nanosleep_10ns); MUSL_BENCHMARK(Bm_function_Nanosleep_100ns); MUSL_BENCHMARK(Bm_function_Tzset); +MUSL_BENCHMARK(Bm_function_Clock_nanosleep_realtime); +MUSL_BENCHMARK(Bm_function_Clock_nanosleep_realtime_raw); +MUSL_BENCHMARK(Bm_function_Clock_nanosleep_realtime_coarse); +MUSL_BENCHMARK(Bm_function_Clock_nanosleep_monotonic); +MUSL_BENCHMARK(Bm_function_Clock_nanosleep_monotonic_raw); +MUSL_BENCHMARK(Bm_function_Clock_nanosleep_monotonic_coarse); +MUSL_BENCHMARK(Bm_function_Clock_nanosleep_boottime); #endif \ No newline at end of file