libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

commit 8b9b778ae8197e8a17af2edcc29965187b500c0a
parent bbb9cc6dae1094fe32e4df69b38842b1f12d65e4
Author: Remy Noulin <loader2x@gmail.com>
Date:   Thu, 27 Jan 2022 21:58:32 +0200

add bt in allocG, getOTypeG, pushG, dupG, trimG, sliceG and splitG

README_bt.md              | 46 +++++++++++++++++++++++
release/libsheepyObject.h | 94 +++++++++++++++++++++++++++++++++++++++++++----
src/libsheepyObject.h     | 94 +++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 218 insertions(+), 16 deletions(-)

Diffstat:
AREADME_bt.md | 46++++++++++++++++++++++++++++++++++++++++++++++
Mrelease/libsheepyObject.h | 94++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Msrc/libsheepyObject.h | 94++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 218 insertions(+), 16 deletions(-)

diff --git a/README_bt.md b/README_bt.md @@ -0,0 +1,46 @@ +TODO what are bt, vbt, dbt? + +# Libsheepy bt (bytes type) performance + +``` +- times are in ms + bt sds diff +trim 25 105 4x +slice/sdsrange 11 77 7x +push/sdscat 165 186 1.13x +split (dbt) 25 138 5.52x (with vbt: 49ms) +short split (vbt) 191 520 2.72x (with static array: 14ms, with dbt: 240ms) + +- allocation count + bt sds +trim 1 1000000 +slice/sdsrange 1 1000000 +push/sdscat 15 16 +split (dbt) 329 10000 (with vbt: 10000) +short split (dbt) 20001 70000 (with static array: 1, with vbt: 50000) + +- heap usage in kb + bt sds diff +trim 4 1000 +slice/sdsrange 4 1000 +push/sdscat 139 128 +split (dbt) 360 370 (with vbt: 940) +short split (vbt) 4000 1474 (with static array: 4, with dbt: 10000) +``` + +- The trim test calls the trim function 1 million times. +- The slice test calls the slice function 1 million times. +- The push test appends the string "%d ",i with int i going from 0 to 1 million +- The split test splits the result from the push test and generates a list with 1 million tokens +- The short split test splits a string of 5 tokens 1 million times + +libsheepy trim doesn't call memmove whereas sdstrim destroys the input by calling memmove. +libsheepy slice doesn't call memmove whereas sdsrange destroys the input by calling memmove. + +sdscat has a good performance because of allocation mechanism. + +libsheepy split (with dbt: dynamic segmented bt array) has a good performance because only malloc is called when building the list whereas sdssplitlen calls realloc. + +The short split test is dominated by malloc and free and the data structure requiring the less malloc/free is vbt. + +libsheepy bt is faster than sds since there are less memory allocations and less calls to memmove. diff --git a/release/libsheepyObject.h b/release/libsheepyObject.h @@ -157,7 +157,11 @@ static const bool checkObjectTypes = true; char *: allocSmallString, \ const char *: allocSmallString, \ char **: allocArraySmallArray, \ - const char **: allocCArraySmallArray \ + const char **: allocCArraySmallArray, \ + bt: allocB, \ + const bt: allocB, \ + bt*: allocPB, \ + const bt*: allocPB \ )(value) @@ -329,6 +333,10 @@ void terminateManyOF(void *paramType, ...); char***: "char***", \ void*: "void*", \ FILE*: "FILE*", \ + bt: "bt", \ + bt*: "bt*", \ + const bt: "const bt", \ + const bt*: "const bt*", \ default: NULL \ ) @@ -692,7 +700,33 @@ void finishManyOF(void *paramType, ...); char: listPushCharS, \ int: listPushCharS, \ default: listPushS \ - ) \ + ), \ + bt: _Generic(value, \ + const char *: pushB, \ + char *: pushB, \ + const bt: pushBB, \ + bt: pushBB, \ + const bt*: pushBPB, \ + bt*: pushBPB, \ + default: pushB \ + ), \ + bt*: _Generic(value, \ + const char *: bPushB, \ + char *: bPushB, \ + const bt: bPushBB, \ + bt: bPushBB, \ + const bt*: bPushBPB, \ + bt*: bPushBPB, \ + default: bPushB \ + ), \ + const bt*: _Generic(value, \ + const char *: pushPB, \ + char *: pushPB, \ + const bt: pushPBB, \ + bt: pushPBB, \ + const bt*: pushPBPB, \ + bt*: pushPBPB, \ + default: pushPB) \ )(self, value) #define pushNFreeO(self, value) (self)->f->pushNFree(self, value) @@ -3737,7 +3771,9 @@ void finishManyOF(void *paramType, ...); char *: dupS,\ const char *: dupS,\ char **: listDupS, \ - const char **: listDupCG \ + const char **: listDupCG, \ + bt: dupB, \ + bt*: dupPB \ )(self) #define replaceO(self, olds, news, max) (self)->f->replace(self, olds, news, max) @@ -5155,7 +5191,11 @@ void finishManyOF(void *paramType, ...); smallArrayt *: trimSmallArrayG, \ smallDictt *: trimSmallDictG, \ smallJsont *: trimSmallJsonG, \ - smallStringt *: trimSmallStringG \ + smallStringt *: trimSmallStringG, \ + bt: trimB, \ + const bt: trimB, \ + bt*: bTrimB, \ + const bt*: trimPB \ )(self) #define lTrimO(self) (self)->f->lTrim(self) @@ -5206,7 +5246,11 @@ void finishManyOF(void *paramType, ...); char ***: iListSliceS, \ smallArrayt *: sliceSmallArrayG, \ smallJsont *: sliceSmallJsonG, \ - smallStringt *: sliceSmallStringG \ + smallStringt *: sliceSmallStringG, \ + bt: sliceB, \ + const bt: sliceB, \ + bt*: bSliceB, \ + const bt*: slicePB \ )(self, start, end) @@ -6623,7 +6667,8 @@ void finishManyOF(void *paramType, ...); char: splitCharSmallJsonG, \ int: splitCharSmallJsonG, \ smallJsont *: splitSmallJsonSmallJsonG, \ - smallStringt *: splitSmallStringSmallJsonG \ + smallStringt *: splitSmallStringSmallJsonG, \ + default: splitSmallJsonG \ ), \ smallStringt *: _Generic(delim, \ char *: splitSmallStringG, \ @@ -6631,8 +6676,41 @@ void finishManyOF(void *paramType, ...); char: splitCharSmallStringG, \ int: splitCharSmallStringG, \ smallJsont *: splitSmallJsonSmallStringG, \ - smallStringt *: splitSmallStringSmallStringG \ - ) \ + smallStringt *: splitSmallStringSmallStringG, \ + default: splitSmallStringG \ + ), \ + bt: _Generic(delim, \ + char*: splitCharB, \ + const char*: splitCharB, \ + bt: splitB, \ + const bt: splitB, \ + bt*: splitDPB, \ + const bt*: splitDPB, \ + default: splitB), \ + const bt: _Generic(delim, \ + char*: splitCharB, \ + const char*: splitCharB, \ + bt: splitB, \ + const bt: splitB, \ + bt*: splitDPB, \ + const bt*: splitDPB, \ + default: splitB), \ + bt*: _Generic(delim, \ + char*: splitPCharB, \ + const char*: splitPCharB, \ + bt: splitPB, \ + const bt: splitPB, \ + bt*: splitPDPB, \ + const bt*: splitPDPB, \ + default: splitPB),\ + const bt*: _Generic(delim, \ + char*: splitPCharB, \ + const char*: splitPCharB, \ + bt: splitPB, \ + const bt: splitPB, \ + bt*: splitPDPB, \ + const bt*: splitPDPB, \ + default: splitPB)\ )(self, delim) //TODO create splitS generic diff --git a/src/libsheepyObject.h b/src/libsheepyObject.h @@ -157,7 +157,11 @@ static const bool checkObjectTypes = true; char *: allocSmallString, \ const char *: allocSmallString, \ char **: allocArraySmallArray, \ - const char **: allocCArraySmallArray \ + const char **: allocCArraySmallArray, \ + bt: allocB, \ + const bt: allocB, \ + bt*: allocPB, \ + const bt*: allocPB \ )(value) @@ -329,6 +333,10 @@ void terminateManyOF(void *paramType, ...); char***: "char***", \ void*: "void*", \ FILE*: "FILE*", \ + bt: "bt", \ + bt*: "bt*", \ + const bt: "const bt", \ + const bt*: "const bt*", \ default: NULL \ ) @@ -692,7 +700,33 @@ void finishManyOF(void *paramType, ...); char: listPushCharS, \ int: listPushCharS, \ default: listPushS \ - ) \ + ), \ + bt: _Generic(value, \ + const char *: pushB, \ + char *: pushB, \ + const bt: pushBB, \ + bt: pushBB, \ + const bt*: pushBPB, \ + bt*: pushBPB, \ + default: pushB \ + ), \ + bt*: _Generic(value, \ + const char *: bPushB, \ + char *: bPushB, \ + const bt: bPushBB, \ + bt: bPushBB, \ + const bt*: bPushBPB, \ + bt*: bPushBPB, \ + default: bPushB \ + ), \ + const bt*: _Generic(value, \ + const char *: pushPB, \ + char *: pushPB, \ + const bt: pushPBB, \ + bt: pushPBB, \ + const bt*: pushPBPB, \ + bt*: pushPBPB, \ + default: pushPB) \ )(self, value) #define pushNFreeO(self, value) (self)->f->pushNFree(self, value) @@ -3737,7 +3771,9 @@ void finishManyOF(void *paramType, ...); char *: dupS,\ const char *: dupS,\ char **: listDupS, \ - const char **: listDupCG \ + const char **: listDupCG, \ + bt: dupB, \ + bt*: dupPB \ )(self) #define replaceO(self, olds, news, max) (self)->f->replace(self, olds, news, max) @@ -5155,7 +5191,11 @@ void finishManyOF(void *paramType, ...); smallArrayt *: trimSmallArrayG, \ smallDictt *: trimSmallDictG, \ smallJsont *: trimSmallJsonG, \ - smallStringt *: trimSmallStringG \ + smallStringt *: trimSmallStringG, \ + bt: trimB, \ + const bt: trimB, \ + bt*: bTrimB, \ + const bt*: trimPB \ )(self) #define lTrimO(self) (self)->f->lTrim(self) @@ -5206,7 +5246,11 @@ void finishManyOF(void *paramType, ...); char ***: iListSliceS, \ smallArrayt *: sliceSmallArrayG, \ smallJsont *: sliceSmallJsonG, \ - smallStringt *: sliceSmallStringG \ + smallStringt *: sliceSmallStringG, \ + bt: sliceB, \ + const bt: sliceB, \ + bt*: bSliceB, \ + const bt*: slicePB \ )(self, start, end) @@ -6623,7 +6667,8 @@ void finishManyOF(void *paramType, ...); char: splitCharSmallJsonG, \ int: splitCharSmallJsonG, \ smallJsont *: splitSmallJsonSmallJsonG, \ - smallStringt *: splitSmallStringSmallJsonG \ + smallStringt *: splitSmallStringSmallJsonG, \ + default: splitSmallJsonG \ ), \ smallStringt *: _Generic(delim, \ char *: splitSmallStringG, \ @@ -6631,8 +6676,41 @@ void finishManyOF(void *paramType, ...); char: splitCharSmallStringG, \ int: splitCharSmallStringG, \ smallJsont *: splitSmallJsonSmallStringG, \ - smallStringt *: splitSmallStringSmallStringG \ - ) \ + smallStringt *: splitSmallStringSmallStringG, \ + default: splitSmallStringG \ + ), \ + bt: _Generic(delim, \ + char*: splitCharB, \ + const char*: splitCharB, \ + bt: splitB, \ + const bt: splitB, \ + bt*: splitDPB, \ + const bt*: splitDPB, \ + default: splitB), \ + const bt: _Generic(delim, \ + char*: splitCharB, \ + const char*: splitCharB, \ + bt: splitB, \ + const bt: splitB, \ + bt*: splitDPB, \ + const bt*: splitDPB, \ + default: splitB), \ + bt*: _Generic(delim, \ + char*: splitPCharB, \ + const char*: splitPCharB, \ + bt: splitPB, \ + const bt: splitPB, \ + bt*: splitPDPB, \ + const bt*: splitPDPB, \ + default: splitPB),\ + const bt*: _Generic(delim, \ + char*: splitPCharB, \ + const char*: splitPCharB, \ + bt: splitPB, \ + const bt: splitPB, \ + bt*: splitPDPB, \ + const bt*: splitPDPB, \ + default: splitPB)\ )(self, delim) //TODO create splitS generic