SPO600 Project – Rejected Functions (stage 3)

This blog is focused on the functions that I found out are not optimizable from either testing or just studying the code. I am doing this since Chris told us to talk about the reason why we think a function cannot be optimized and if we ever come across them to blog about it.


The difftime.c function is very simple to understand, it just gives us the difference there is between 2 time that are passed into the function. My notes were in the compactness of the code and the fluency of it. For this function, the code was very short compared to other functions in the same library, I noticed that it had a inner function called subtract that returns the amount of time difference between the two time parameters with a data type of time_t. I looked at it and there was really nothing to be done in that function, subtract, when it comes to optimization.

After that I looked to the __difftime function, original library function, and it just had a couple of if statements checking for the double rounding errors and it returns the difference in time between the two. Therefore, I concluded that this function is not able to be optimized since there are no redundancies in this code and no other way to make it faster.



Screenshot from 2017-04-22 20-22-41

After running the code in the for loop this was time it took to end. As it seems the time was most likely consumed by the text I printed in the for loop. Now lets try it without any text.



As you can see now it only takes the program 9/100 of a second to run through the iteration, meaning that if we only calculate the time when this difftime() function is running it would be virtually 0. Therefore, this function is not optimizable.



At first I thought I was going to be able to optimize it but then i started to understand the purpose of this function and I realized that I was not able to do it. This function is mostly dependent on other functions, like memset and malloc, that just deal with memory transformation and allocation. Another thing I noticed is the use of struct in the function, the moment I realized that I though about the use of union over structs but as I started to think of the differences and uses of structs and unions it made more sense to use structs, because some of the variables within the structs are being used at the same time. Therefore, the only way this function can be optimized, in my opinion, is just optimizing the other functions it works with (memset and malloc), not its own source code.

No test was done to prove this since there was no way I could test this function in particular. There was no test in the library done to this, and could not find any test done to this function online.


This function is also very dependent on other functions, like malloc and realloc, because of this it would put it in the same situation as the alt_digit which the only optimization possible would be on the functions it uses not on its own source code. Also, the compiler already does all the optimization needed when it comes to branch prediction and predication of the if statements of the function. Therefore, nothing to be done in this one when it comes to optimization.

No test was done to prove this since there was no way I could test this function in particular. There was no test in the library done to this, and could not find any test done to this function online.


The wctype.c source code was very compact, lacks redundancy. It was also dependent of other functions for the most part, like strlen, and memcmp, which I believe are being optimized by my classmates as we speak. Because of this, the function cannot be really optimized by changing something on its source code but just by optimizing the other functions it relies on to work.

While I was looking at it I found strange that the for loop did not have any termination condition within the parameters of the for loop but that it had them inside the commands in the for loop. That to me was pretty cool, I had never seen it before.



Screenshot from 2017-04-22 20-52-00

Screenshot from 2017-04-22 20-46-11

I found this test file in the directory wctype, and looked at the source code of the function. It was really good since it tests everything that the function can do. The results were that it ran the test in 1/100 of a second, meaning that, as I said before, this function is  not optimizable.


Like some of the other functions this one looked very compact, not a lot of source code. It seemed that was relies on other functions like strcmp, and strchr, both of which are being optimized by my classmates. The only way I see that this function can be optimized is if these other functions are also optimized.

I did not really know how to test this function in particular, so I went online to try and see a test function for it and could not find any, but I found this interesting function using it along with other functions in this directory.

Screenshot from 2017-04-22 21-01-23


Well those are some of the functions that I looked at but could not really think of a way I could optimize them. I noticed that most of them rely on other functions in the glibc to work, this was really interesting since I thought at he beginning of this project that each one would have their own inner functions to deal with most of the commands it needed.

This semester in particular was very challenging due to my sickness, and I did not really have much time to work on this project at all. I really wish I had more time but since the semester it’s over already, there is nothing more to be done other than this. I really got some appreciation to the whole open source movement, and to assembly as a language (which is really hard).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s