Not to think about solutions, but discover, quantify, invent, build, deploy, and support solutions to problems. As developers, we are charged with making things better in a timely and efficient fashion. So, the moral of the story is that Occam's Razor certainly applies in programming. Luckily, the buzzy solution was almost as fast and almost as light on memory, meaning that it would have been almost worth using if it didn't take 6x longer to implement. My initial solution using a while loop and some variables took me about 5 minutes to come up with. Building this generator, thinking through it from a memory and performance standpoint, writing it, and profiling it took me about 30 minutes. So, in conclusion, I used a language-specific feature that is pretty buzzy in Python because it is supposed to accomplish this kind of work better than a solution that is more "off-the-top-of-your-head". The code is as follows:Īnd the results of that are represented as the graph below: The final solution I had was to write my own generator based on a generator I found in the Python documentation and make it as efficient as possible for this purpose. But apparently not to use, which is kinda the whole point in my eyes really. The main advantage of a generator over a list is that it takes much less memory. Don't believe me, take a look at this sentence from an article on : But a generator is supposed to rely less on memory. Please know also, that I am not criticising the solution provided by it was just an example of using a generator to accomplish this task. AND IT TOOK LONGER TO DO IT by almost two seconds. As in more than 1000x more memory than the iterator function. WHAT?!? I was expecting something completely different! At the peak of this chart, right around 14.5 seconds, the generator function is using almost 2GB of memory! 2 GIGABYTES. Enter fullscreen mode Exit fullscreen modeĪnd below is the corresponding graph of usage over time:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |