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

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 19 22:17:07 PDT 2015


On 3/19/2015 9:59 AM, "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= 
<ola.fosheim.grostad+dlang at gmail.com>" wrote:
> On Thursday, 19 March 2015 at 00:42:51 UTC, weaselcat wrote:
>> On Wednesday, 18 March 2015 at 12:59:17 UTC, bearophile wrote:
>>> High level constructs in D are often slower than low-level code, so in some
>>> cases you don't want to use them.
>>
>> I actually found that LDC does an _amazing_ job of optimizing high level
>> constructs and converting "low level" code to higher level functional code
>> resulted in minor speedups in a lot of cases.
>>
>>
>> (Other performance benefits include the algorithm primitives being extensively
>> optimized in phobos.)
>
> If the code/compiler generates suboptimal code in the first place then
> improvements can be somewhat random. But if you write code with good cache
> locality, filling the pipeline properly then there is no alternative to going
> low level.
>
> Btw, take a look at this:
> http://stackoverflow.com/questions/28922323/improving-line-wise-i-o-operations-in-d
>
> That's really bad marketing...

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:
----------
import std.stdio;
import std.string;
import std.file;

int main(string[] args)
{
   if (args.length < 2) {
     return 1;
   }
   auto c = cast(string) read(args[1]);
   auto l = splitLines(c);
   writeln("There are ", l.length, " lines.");
   return 0;
}
---------
allocates memory for all the lines and an array of them. No wonder it's slow! 
The allocations are slow, and filling them all when they are cold-cached - 
AWFUL! (It also uselessly and maddeningly auto-decodes, a misfeature of Phobos 
if there ever was one.)

http://dlang.org/phobos/std_string.html#.splitLines


More information about the Digitalmars-d mailing list