I created something much faster than a std::string

Welcome everyone 👋

I work as a freelancer in C++.

some time ago a company asked me to work on a special type of database system and their condition was that the system be very fast, faster than any known database!

I did this already and it turns out…


This content originally appeared on DEV Community and was authored by Maysara

Welcome everyone 👋

I work as a freelancer in C++.

some time ago a company asked me to work on a special type of database system and their condition was that the system be very fast, faster than any known database!

I did this already and it turns out that my system is 50 times faster than MySQL!

The work was done, I received my salary and everything was fine.

But they contacted me a few days ago and told me why don't you try to develop the system further? And i agreed.

I tested just about everything, everything was perfect except for a few things like:
std::string, std::vector.

I created mini libraries from those to compare performance and was surprised that what I did was much faster!

Therefore, I developed a special string system and wanted to share it with you for the benefit, and also to benefit from your suggestions and experience.

System Features:

  • Much faster than std::string.

  • Easy to use.

  • It was designed as part of a large database so it is very fast and good at handling memory.

  • Responsive to all types of data, you can enter characters, numbers, even decimal numbers, boolean values ​​or even lists, without the need to convert data types to a string.

  • It contains a system dedicated to calculating numbers and converting them into text strings, It works great with decimal numbers. see below to learn more.

  • All functions tested, no errors detected.

The reason for the speed of performance:

The reason lies in the way I handle the heap memory, I don't need to realloc memory every time the value changes, and I don't need to completely reset the object when any modification is made.

If you are interested you can check out the set() function, i have left comments that can explain this further.

Test results:

+-------------------------+--------+------+------------------------------+
|METHOD                   |CLASS   |TIME  |NOTES                         |
+-------------------------+--------+------+------------------------------+
|create empty             |xstring |210   |                              |
|                         |string  |1586  |                              |
+-------------------------+--------+------+------------------------------+
|create by string         |xstring |1859  |                              |
|                         |string  |3194  |                              |
+-------------------------+--------+------+------------------------------+
|create by character      |xstring |1852  |                              |
|                         |string  |2680  |Unavailable, used to_string() |
+-------------------------+--------+------+------------------------------+
|create by bool           |xstring |1836  |                              |
|                         |string  |2487  |Unavailable, used to_string() |
+-------------------------+--------+------+------------------------------+
|create by integer        |xstring |2477  |                              |
|                         |string  |2453  |Unavailable, used to_string() |
+-------------------------+--------+------+------------------------------+
|create by decimal        |xstring |4428  |                              |
|                         |string  |23053 |Unavailable, used to_string() |
+-------------------------+--------+------+------------------------------+
|create by same object    |xstring |3750  |                              |
|                         |string  |9779  |                              |
+-------------------------+--------+------+------------------------------+
|create by multiple       |xstring |3726  |                              |
|                         |string  |--    |Unavailable                   |
+-------------------------+--------+------+------------------------------+
|append                   |xstring |2426  |                              |
|                         |string  |7685  |                              |
+-------------------------+--------+------+------------------------------+
|prepend                  |xstring |2593  |                              |
|                         |string  |10665 |Unavailable, used insert(0,)  |
+-------------------------+--------+------+------------------------------+
|insert                   |xstring |2574  |                              |
|                         |string  |10579 |                              |
+-------------------------+--------+------+------------------------------+
|compare                  |xstring |3985  |                              |
|                         |string  |8200  |                              |
+-------------------------+--------+------+------------------------------+
|swap                     |xstring |3928  |                              |
|                         |string  |11579 |                              |
+-------------------------+--------+------+------------------------------+
|to lower                 |xstring |2407  |                              |
|                         |string  |--    |Unavailable                   |
+-------------------------+--------+------+------------------------------+
|to upper                 |xstring |2432  |                              |
|                         |string  |--    |Unavailable                   |
+-------------------------+--------+------+------------------------------+
|select by index          |xstring |1984  |                              |
|                         |string  |3303  |                              |
+-------------------------+--------+------+------------------------------+
|select by char and pos   |xstring |1976  |                              |
|                         |string  |4138  |                              |
+-------------------------+--------+------+------------------------------+
|select last              |xstring |1910  |                              |
|                         |string  |3563  |                              |
+-------------------------+--------+------+------------------------------+
|pop last                 |xstring |2114  |                              |
|                         |string  |4338  |                              |
+-------------------------+--------+------+------------------------------+
|pop by index             |xstring |2095  |                              |
|                         |string  |6591  |                              |
+-------------------------+--------+------+------------------------------+
|reverse                  |xstring |2465  |                              |
|                         |string  |--    |Unavailable                   |
+-------------------------+--------+------+------------------------------+
|find first of            |xstring |2001  |                              |
|                         |string  |4446  |                              |
+-------------------------+--------+------+------------------------------+
|find last of             |xstring |1979  |                              |
|                         |string  |4199  |                              |
+-------------------------+--------+------+------------------------------+
|sub string               |xstring |4070  |                              |
|                         |string  |17287 |                              |
+-------------------------+--------+------+------------------------------+
|is empty                 |xstring |1909  |                              |
|                         |string  |3262  |                              |
+-------------------------+--------+------+------------------------------+

Test Info

  • OS linux, ubuntu 20.04

  • processor Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz

  • memory 8064MiB System memory

  • Compiler g++ 11

  • C++ Version c++ 20

  • tested by valgrind, you can test with just run script and you will got same ratios

You can find the source file and test script here GitHub: xString

I have some questions :

  1. Are there any errors that I did not notice?

  2. Is there anything that can be done to improve performance?

  3. Is there anything missing?

  4. What is your opinion and what are your suggestions?


This content originally appeared on DEV Community and was authored by Maysara


Print Share Comment Cite Upload Translate Updates
APA

Maysara | Sciencx (2022-04-09T03:10:21+00:00) I created something much faster than a std::string. Retrieved from https://www.scien.cx/2022/04/09/i-created-something-much-faster-than-a-stdstring/

MLA
" » I created something much faster than a std::string." Maysara | Sciencx - Saturday April 9, 2022, https://www.scien.cx/2022/04/09/i-created-something-much-faster-than-a-stdstring/
HARVARD
Maysara | Sciencx Saturday April 9, 2022 » I created something much faster than a std::string., viewed ,<https://www.scien.cx/2022/04/09/i-created-something-much-faster-than-a-stdstring/>
VANCOUVER
Maysara | Sciencx - » I created something much faster than a std::string. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/09/i-created-something-much-faster-than-a-stdstring/
CHICAGO
" » I created something much faster than a std::string." Maysara | Sciencx - Accessed . https://www.scien.cx/2022/04/09/i-created-something-much-faster-than-a-stdstring/
IEEE
" » I created something much faster than a std::string." Maysara | Sciencx [Online]. Available: https://www.scien.cx/2022/04/09/i-created-something-much-faster-than-a-stdstring/. [Accessed: ]
rf:citation
» I created something much faster than a std::string | Maysara | Sciencx | https://www.scien.cx/2022/04/09/i-created-something-much-faster-than-a-stdstring/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.