A few notes on choosing between Go and D for a quick project

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Mar 20 03:50:30 PDT 2015


On 3/20/2015 12:42 AM, Paulo Pinto wrote:
> On Friday, 20 March 2015 at 05:17:11 UTC, Walter Bright wrote:
>> Sigh. The Python version:
>> -----------
>> import sys
>>
>> if __name__ == "__main__":
>>     if (len(sys.argv) < 2):
>>         sys.exit()
>>     infile = open(sys.argv[1])
>>     linect = 0
>>     for line in infile:
>>         linect += 1
>>     print "There are %d lines" % linect
>> ----------
>> does not allocate memory. The splitLines() version:
>> [...] cutted
>
> Of course it does allocate memory.
>
> Python's "for...in" makes use of iterators and generators, already there you
> have some allocations going around.
>
> Not only that, there is one string being allocated for each line in the file
> being read, even if it isn't used.

Since 'line' is never referred to again after constructed, even a simple 
optimizer could elide it.

It would be easy to test - accumulate the lines in an array, and check the times.



More information about the Digitalmars-d mailing list