Code executes slower after declaring variables with their respective types instead of double type
Ältere Kommentare anzeigen
Hello,
I'm working on a code which can be divided in two parts.
The first part consists of reading the input files from csv-files and storing them as variables.
The second part consists of manipulating those variables in order to get the different results.
Until recently all the variables were stored as double type. In order to reduce the execution time of the code we decided to store each variable with their most suitable type. For example the age of a person would be a uint8-type.
After I changed the code I made a performance test with a small part of the input files. Unfortunately, the change did not bring the performance improvement we expected, the change even slowed down the code.
All Double Most suited type
Part 1 30s 50s
Part 2 60s 80s
Total 90s 130s
This would mean the execution of the code with all the input files would take about 44% more time than previously from 35min run-time to 50 minute run-time.
Before the change the variables were read with the sscanf function from the csv-files. The result of the sscanf function is than stored as a double. (Because that's what sscanf does and there is no way to change it?)
After the change the variables are simply read as a string and then stored with their respective type (With the help of a hash-table, which gives the respective type of every variable).
Is there an explanation why the execution time of my code increased, even though I changed the data-types of the variables in order to free up memory space?
I would specifically like to know why the calculating part (Part 2) of my code has slowed down after the change. Because I did not change this part of the code the only thing that happened is the fact that the variables have different types and take less memory space.
Thank you very much,
Luca
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Variables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!