Home

Awesome

Introduction

The goal of this project is to compare several C libraries that provide some STL like capabilities of the C++ (container template) but are targeting classic C language. A STL like library for C is a C library providing several classic generic containers for the C language, like vector, list, map, unordered_map, and so on.

A small benchmark to compare their performance is includes in the bench directory.

To do this, the same simple programs will be implemented by the libraries in the more straight-forward way possible, for different kind of containers and for different types. Then the API ergonomics of each programs can be compared each other according to the user taste.

Objective characteristics of the libraries are directly compared in this file.

Disclaimer

I am the main author of M*LIB, one of theses libraries.

This work is still a WIP.

Test Program

Rules

The test program shall respect the following conditions:

A workaround is defined as a way to implement this program which is not natural for the library. This typically includes:

For example, if a container library manual requests to define some macro for its use, then it won't be considered as a workaround.

Array tests

The program shall perform the following operations:

Associative array tests

The program shall perform the following operations:

Execution

The different programs are available in this repository. To build then, you just need to have a working C11 compiler, a make tool, git the GMP library, and the GLIB library to build then.

Simply run "make" to perform a clone of the projects and generate the different executables.

Analysis and synthesis

The following characteristics are used to compare the different C libraries. The C++ STL is also included as as reference.

Synthesis

CharacteristicsSTLM*LIBSTCCMCCTLCollectionsCCCGLIB
C languageNA>=C99>=C99>=C99>=C99>=C99>=C11* or >=C23>= C89
Pure CNAYYYYYYY
Header onlyYYYYYNYN
Generic mechanismtemplateFEFEACA
type safeYYYYYNY*N
integer/float supportYYYYYYYY*
struct POD supportYYYYYNYY*
No default steal of ownershipYYYNNYNY
Optional move semanticsYYNNNNNN
C++ class supportYYNNNNNN
C object supportYYYYYNYY*
container/basic spatial separationYYNNNNAYNA
API Interface AdaptatorNYNNNNNN
basic emplace supportYYYNNNNN
Enhance emplace supportYYNNNNNN
Iterator supportYYYNYYYN
Sort algorithmYYYNYYNY
Enhanced Sort algorithmYYYNYYNY
single linkage definitionN*YYYNYNY
Full abstractionYYNYNYYN
Contract violation checksYYNNNNNN
Natural usageYNNNNNNN
Basic type is storedYYYYYNYN
No explicit instanciationYNNNNYYY
prefixed functionYYYYYYYY
memory handlingexceptionabort, exceptionretcoderetcodenoneretcoderetcoderetcode
destructors on exceptionYY*NANANANANAN
custom memory supportYYYYNYYN
context for custom memory supportNNYNNNNN
Forward declaration supportNNYNNNNN
SerializationNYNNNNNN
JSON SerializationNYNNNNNN
XML SerializationNNNNNNNN
Comparison programsSTLM*LIBSTCCMCCTLCollectionsCCCGLIB
int:number of characters2363704801011593874604696
int:number of line of codes1216263622353038
int:number of workarounds00022110
mpz:number of characters26150011521859145612881108840
mpz:number of line of codes1318365237583947
mpz:number of workarounds00386120
ContainersSTLM*LIBSTCCMCCTLCollectionsCCCGLIB
Singly Linked Non-Intrusive listYYNNYYNY
Doubly Linked Non-Intrusive listYNNNYYYY
Singly Linked, Dualy Push Non-Intrusive listNYYNNNNN
Singly Linked Intrusive listNNNNNNNN
Doubly Linked Intrusive listNYNNNNNN
Dynamic arrayYYYYYYYY
Static arrayYNNNYNNN
pairYYNNNNNN
tupleYYNNNNNN
optionalYYNNNNNN
variantYYNNNNNY
bitsetYYYYNNNN
Dynamic character stringYYYNYNNY
string_viewYNYNNNNN
dequeYYYYYYNY
queueYYYYYYNY
priority queueYYYYYYNN
stackYYYNYYNN
Bounded QueueNYNNNNNY
setYYYNNYNY
multisetYYNNNNNN
mapYYNNYYNN
multimapYYNNNNNN
unordered_setYYYYYYYN
unordered_multisetYNNYNNNN
unordered_mapYYYYYYYN
unordered_multimapYNNYNNNY
flat_setYNNYNNNN
flat_multisetYNNYNNNN
flat_mapYNNYNNNN
flat_multimapYNNYNNNN
unique_ptrYNYNNNNN
shared_ptrYYYNNNNN
weak_ptrYNNNNNNN
Function ObjectYYNNNNNN
SpanYNYNNNNN
MDSpanYNYNNNNN
Bounded StringNYNNNNNN
Atomic Shared Register SPSCNYNNNNNN
Atomic Shared Register MPSCNYNNNNNN
Atomic Shared Register SPMCNYNNNNNN
Atomic Shared Register MPMCNYNNNNNN
concurrent<>NYNNNNNN
Skip ListNNNYNNNN
Sorted Bidirectional MapNNNYNNNN
TreeNYNNNNNN
AlgorithmsSTLM*LIBSTCCMCCTLCollectionsCCCGLIB
TODOYYYNYYYY

The used versions are:

COMPONENTVERSION
GCC10.2
C Macro Collectionsv0.23.1
CollectionsCff1be366329e2c82cd85b2c803114ef8d2115f7f
CTL3923e6776a231e5d58cf91225ca8a1d61879401b
M*LIBa0818419ab959e05517336e1bea699c1854b29f3
STC5fb5ed08250b5ad4eadd6e7a9fdc44f4519b15ff
CC2012d9d2eb8f035d7dc69f36ec03ca3199ede1bf
GLIB2.74

This is a WIP, and some reviews are needed to help this comparison.

If you see any mistakes in this report, or want to include another C library, or want to include another point of comparison, do not hesitate to open a pull request.