C++ Reading From File

When reading data from a file multiple times, there are basically two main ways to do so. You can either always reopen the file or you can keep the file open and jump to a specific location. With the option to jump to a specific location inside the file, I was wondering exactly how much faster it is to use this function over re-opening the file every time.

Initially my question was more why would anyone re-open a file when C++ offers a way to reset the file pointer to the beginning of the file? In my mind there is no way that the latter could be any faster, and since both have the same effect why ever bother? But of course I had to put my idea to the test.

Continue reading


C++ Array vs Vector

I always believed that using a primitive type, or native array would be more performant compared to using a vector. However, the C++ standard book says that you should always use a vector. This sounds odd to me as why would you use a dynamic length variable if you want to have a fixed size list? The big problem with C++ (or actually C) arrays is that it has no built-in length like Java has. However there also exists a standard array class, which seems to fill this gap. So it is time to see how these three different options perform.

Continue reading

SQL Perfomance Test

Relational databases have been around for a very long time and they have evolved up to the point where they can handle processing millions of results within seconds. But for someone like me having a query that performs good isn’t enough, I am constantly wondering whether there is a way I can speed things up, whether there is a more efficient way to do it.

Recently I had to refactor part of an application which contained some queries. And at first glance, I could already tell the queries wouldn’t be as efficient as they could be, but before rewriting them, I decided to have a small experiment to determine the best approach to write them. The main concern I had with theses queries was how they gathered data from different tables. That will be the focus of this blog post.

Continue reading

C++ Converting Integer/Double To String

In my previous blog post, we noticed that concatenating strings was a mixed story depending on whether it were all real strings, or if you were mixing strings with integers and doubles. To understand the full picture we need to investigate how much of a penalty was taken because of the different way to convert the integer or double to a string. In this blog post, we will do exactly that.

Continue reading

C++ String Concatenation Appendix

In my previous blog post I compared the different ways of concatenating a string in C++. I did however miss one very obvious way to do this. In contrary to Java (where a String is immutable), C++ just offers an append method on a string. In this short blog post I repeat the previous test but now include the append method from string.

Continue reading

C++ String Concatenation

String concatenation is a very common operation to be done. From my time with Java, I have been warned many times that naive string concatenation could destroy the performance of your application. This is because the system has to create a lot of in-between strings, causing many copy operations to be executed. Instead you should use the provided StringBuilder.

Now that I came across a similar situation in C++, I was wondering whether the same is true here. In this blog post I will compare three different ways to concatenate a string. But I will go the extra mile as well, and see how combining strings and numbers has an effect on the concatenation.

Continue reading

C++ Float vs Double

Since I am no working with C++ and no longer use Java as my mainly programming language, I was wondering whether some of the past experiments would yield different results. In this blog post I will repeat the exercise of comparing floats and doubles but now for C++. Given that Java and C++ do handle types differently it is possible that the results may vary, however both languages implement floating points numbers in the same way, according to the IEEE standard.

Continue reading