I/O operation is very time consuming

I have read that i I/O operation is costly. But to what extent this can effect the application performance ?

I was refactoring code in application which had large I/O operation. Result was that after reducing the number of I/O operations, application was faster by atleast 10 times ( affect was much more than 10 times as I did not measure the exact time difference before and after refactoring the code)

Below is what i refactored

for ( loop through all members of array in memory)
{
for ( all records in table1 )
{

}
}

table1 had 1 million records and the array has 10000 members, number of disk operations required would be 1 million * 1000 ( assuming each record read from table1 is 1 i/o operation ).
Now let’s reverse the loop’s

for ( all records in table1 )
{
for (loop through all members of array in memory)
{

}
}

Now number of disk i/o is 1 million * 1 (as the outer loop loops only once) . Since the array is in memory, access is very very fast when compared to fetching data from disk. I am sure, reversing the loop’s will definitely reduce the time consumed in above case by atleast a factor of 10. Not all loops can be reversed as above as it depends on application business logic too.

Advertisements
This entry was posted in C Section. Bookmark the permalink.

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