Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/npavlinek/memory_allocation_experiment
https://github.com/npavlinek/memory_allocation_experiment
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/npavlinek/memory_allocation_experiment
- Owner: npavlinek
- License: 0bsd
- Created: 2023-04-10T19:06:25.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T15:23:10.000Z (over 1 year ago)
- Last Synced: 2024-10-26T22:31:44.797Z (3 months ago)
- Language: C++
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Memory Allocation Experiment
## About
The experiment was to see whether it is worth it to implement and use a custom memory allocator for performance and code simplicity.
There are three different implementations:
- STL version: using `std::string` and `std::vector`, a fairly standard implementation
- Non-STL version: using only `malloc`, a custom string builder and storing file names as a linked list
- Custom allocator version: the same as the non-STL version, but using a custom linear allocatorThe implementations recursively iterate over all files and directories inside of the current directory, saving all file names into memory.
## Results
Running this program inside the Mozilla source code repository (changeset `66e3220110ba0dd99ba7d45684ac4731886a59a9`):
```
STL version took 5.09 s and found 1062892 items
Non-STL version took 4.13 s and found 1062892 items
Custom allocator version took 4.09 s and found 1062892 items
```In this case the custom allocator version is slightly faster, sometimes it is even faster and other times it is slower than the non-STL version. I still see this as a win though. Even if the custom allocator breaks even with `malloc`, it is still a win because of its' simplicity; the custom allocator is 19 lines of code (depending on how you count code), there is no way `malloc` is anywhere close to that.
## License
Zero Clause BSD License, a public domain equivalent license. See the `LICENSE` file for more details.