From WikiChip
Editing schlemiel the painter's algorithm

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 52: Line 52:
  
 
If the function was to be used on a simple file with 2 lines, function ''file_get_line'' will end up reading line 1 to get the first line and then it will read line one again and line two to get to the second line, resulting in 3 line scans. If the file was to have 10 lines, ''file_get_line'' will end up reading a total of 55 lines (<math>\sum\limits_{i=1}^{10} i</math>) over and over. It can be seen that the number of operations done grows very quickly even for moderately small files. A file with just 10,000 lines which could usually be read in just 10,000 seeks will result in <math>\sum\limits_{i=1}^{10000} i = {50,005,000}</math> seeks with this implementation.
 
If the function was to be used on a simple file with 2 lines, function ''file_get_line'' will end up reading line 1 to get the first line and then it will read line one again and line two to get to the second line, resulting in 3 line scans. If the file was to have 10 lines, ''file_get_line'' will end up reading a total of 55 lines (<math>\sum\limits_{i=1}^{10} i</math>) over and over. It can be seen that the number of operations done grows very quickly even for moderately small files. A file with just 10,000 lines which could usually be read in just 10,000 seeks will result in <math>\sum\limits_{i=1}^{10000} i = {50,005,000}</math> seeks with this implementation.
 
== External links ==
 
* [http://www.joelonsoftware.com/articles/fog0000000319.html Joel Spolsky's Blog Post]
 
  
 
[[category:optimization]]
 
[[category:optimization]]
 
[[category:algorithms]]
 
[[category:algorithms]]

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)