July 24, 2013
On 24 Jul 2013, at 14:49, Chris wrote:
> Thanks for clarifying that. I am still impressed with the performance. Although I'm sure I could squeeze a bit
> more out of dmd. As of now I'm only using the garden-variety (i.e. dmd -release [files]). I didn't use any
> switches with ldc2, though.

Never benchmark programs without at least some optimization flags (e.g. -O for DMD). It does not allow you to draw any conclusions, unless you really want to compare the performance of the compilers for debug builds of your application (where performance usually doesn't matter, except for in realtime-ish applications).

David
July 24, 2013
On Wednesday, 24 July 2013 at 13:29:03 UTC, Chris wrote:
>
> What's the story with LDC for Windows?

There is a MingW32 version of LDC for 32-bit Windows which works pretty well.

I am working on a 64-bit version using MSVC and the MC C Runtime. Because LLVM still lacks support for Structured Exception Handling this is still alpha quality.

Both Windows version appeared with 0.11 and are pretty new.

Kai
July 25, 2013
On Wednesday, 24 July 2013 at 16:56:40 UTC, David Nadlinger wrote:
> On 24 Jul 2013, at 14:49, Chris wrote:
>> Thanks for clarifying that. I am still impressed with the performance. Although I'm sure I could squeeze a bit
>> more out of dmd. As of now I'm only using the garden-variety (i.e. dmd -release [files]). I didn't use any
>> switches with ldc2, though.
>
> Never benchmark programs without at least some optimization flags (e.g. -O for DMD). It does not allow you to draw any conclusions, unless you really want to compare the performance of the compilers for debug builds of your application (where performance usually doesn't matter, except for in realtime-ish applications).
>
> David

I did not do any benchmarking, to be honest. I just found it amazing that the ldc2 compiled program was up immediately (less than a second) and performed, whereas the read-and-parse operation at start-up takes 4 seconds in the dmd compiled version. One of the 4 files is an XML file that I parse with the bad old std.xml module. The remaining 3 are simple text files (no mark up) with simple regex parsing. Using the optimization switches (see earlier comment) with dmd did not help. I wonder why that is. Is it my code or dmd?
July 26, 2013
You can write a simple application, which will only parse that xml file and see, how it performs.
July 29, 2013
On Friday, 26 July 2013 at 05:05:54 UTC, Kagamin wrote:
> You can write a simple application, which will only parse that xml file and see, how it performs.

I isolated the xml parsing and wrote a test program. It turned out that the xml parsing is the culprit.

The average after running it 0..10 times in a loop (if I ran it 100 times, it wouldn't look much different):

dmd 2.063
Average time: 2233 msecs

ldc2
Average time: 10.2 msecs

I used StopWatch based on this example (http://dlang.org/phobos/std_datetime.html#StopWatch).

Running on Ubuntu 12.04 LTS, Intel Core i7-2760QM CPU @ 2.40GHz × 8, 32-bit



July 30, 2013
I have a little question..
Why Digital Mars doesn't uses LLVM for backend and develops their own performance killer ?
Is someone contact with them to drop out their backend ?
July 30, 2013
On Tuesday, 30 July 2013 at 09:10:24 UTC, Temtaime wrote:
> I have a little question..
> Why Digital Mars doesn't uses LLVM for backend and develops their own performance killer ?
> Is someone contact with them to drop out their backend ?

I checked it once more to make sure my code is not the problem. I used the xml parsing example on this page http://dlang.org/phobos/std_xml.html (the second example). I created a dummy "books.xml" file with one entry (see below for source). The result:

Loop: 0..100

DMD 2.063
dmd -release -noboundscheck -O -inline
Average time: 41.88 msecs

LDC2 (latest version, no flags)
ldc2 [files]
Average time: 0.01 msecs

------ D Code -------

import std.xml;
import std.stdio;
import std.string;
import std.datetime;

void main() {
	StopWatch sw;
  enum n = 100;
  TickDuration[n] times;
  TickDuration last = TickDuration.from!"seconds"(0);

  foreach (i; 0..n) {
  	sw.start();
  	parse();
  	//writeln("Time ", sw.peek().msecs, " [ms]");
  	sw.stop();
  	times[i] = sw.peek() - last;
    last = sw.peek();
  }
   real sum = 0;
   // To know the number of seconds,
    // use properties of TickDuration.
    // (seconds, msecs, usecs, hnsecs)
   foreach(t; times) {
   	sum += t.msecs;
   }
   writeln("Average time: ", sum/n, " msecs");
}

struct Book
{
    string id;
    string author;
    string title;
    string genre;
    string price;
    string pubDate;
    string description;
}

void parse() {
	string s = cast(string)std.file.read("books.xml");

    // Check for well-formedness
    check(s);

    // Take it apart
    Book[] books;

    auto xml = new DocumentParser(s);
    xml.onStartTag["book"] = (ElementParser xml)
    {
        Book book;
        book.id = xml.tag.attr["id"];
				
        xml.onEndTag["author"]       = (in Element e) { book.author      = e.text(); };
        xml.onEndTag["title"]        = (in Element e) { book.title       = e.text(); };
        xml.onEndTag["genre"]        = (in Element e) { book.genre       = e.text(); };
        xml.onEndTag["price"]        = (in Element e) { book.price       = e.text(); };
        xml.onEndTag["publish-date"] = (in Element e) { book.pubDate     = e.text(); };
        xml.onEndTag["description"]  = (in Element e) { book.description = e.text(); };

        xml.parse();

        books ~= book;
    };
    xml.parse();

    // Put it back together again;
    auto doc = new Document(new Tag("catalog"));
    foreach(book;books)
    {
        auto element = new Element("book");
        element.tag.attr["id"] = book.id;

        element ~= new Element("author",      book.author);
        element ~= new Element("title",       book.title);
        element ~= new Element("genre",       book.genre);
        element ~= new Element("price",       book.price);
        element ~= new Element("publish-date",book.pubDate);
        element ~= new Element("description", book.description);

        doc ~= element;
    }

    // Pretty-print it
    //writefln(join(doc.pretty(3),"\n"));
}

------ XML FILE ------

<?xml version="1.0" encoding="UTF-8"?>
<books>
	<book id="1-23456789">
		<author>Count Dracula</author>
		<title>D for Vampires</title>
		<genre>Programming</genre>
		<price>66.6</price>
		<publish-date>1897</publish-date>
		<description>Tomb programming with D</description>
	</book>
</books>
July 30, 2013
On Tuesday, 30 July 2013 at 09:10:24 UTC, Temtaime wrote:
> I have a little question..
> Why Digital Mars doesn't uses LLVM for backend and develops their own performance killer ?
> Is someone contact with them to drop out their backend ?

It's not going to happen (any time soon at least).

Luckily, we have ldc and gdc for faster executables. They share the same frontend as dmd (with some modifications) and the differences are closing all the time.
July 30, 2013
try
---
import core.memory;
GC.disable();
---

Maybe GC lags?
July 30, 2013
On Tuesday, 30 July 2013 at 09:21:38 UTC, Chris wrote:
> On Tuesday, 30 July 2013 at 09:10:24 UTC, Temtaime wrote:
>> I have a little question..
>> Why Digital Mars doesn't uses LLVM for backend and develops their own performance killer ?
>> Is someone contact with them to drop out their backend ?
>
> I checked it once more to make sure my code is not the problem. I used the xml parsing example on this page http://dlang.org/phobos/std_xml.html (the second example). I created a dummy "books.xml" file with one entry (see below for source). The result:
>
> Loop: 0..100
>
> DMD 2.063
> dmd -release -noboundscheck -O -inline
> Average time: 41.88 msecs
>
> LDC2 (latest version, no flags)
> ldc2 [files]
> Average time: 0.01 msecs
>
> ------ D Code -------
>
> import std.xml;
> import std.stdio;
> import std.string;
> import std.datetime;
>
> void main() {
> 	StopWatch sw;
>   enum n = 100;
>   TickDuration[n] times;
>   TickDuration last = TickDuration.from!"seconds"(0);
>
>   foreach (i; 0..n) {
>   	sw.start();
>   	parse();
>   	//writeln("Time ", sw.peek().msecs, " [ms]");
>   	sw.stop();
>   	times[i] = sw.peek() - last;
>     last = sw.peek();
>   }
>    real sum = 0;
>    // To know the number of seconds,
>     // use properties of TickDuration.
>     // (seconds, msecs, usecs, hnsecs)
>    foreach(t; times) {
>    	sum += t.msecs;
>    }
>    writeln("Average time: ", sum/n, " msecs");
> }
>
> struct Book
> {
>     string id;
>     string author;
>     string title;
>     string genre;
>     string price;
>     string pubDate;
>     string description;
> }
>
> void parse() {
> 	string s = cast(string)std.file.read("books.xml");
>
>     // Check for well-formedness
>     check(s);
>
>     // Take it apart
>     Book[] books;
>
>     auto xml = new DocumentParser(s);
>     xml.onStartTag["book"] = (ElementParser xml)
>     {
>         Book book;
>         book.id = xml.tag.attr["id"];
> 				
>         xml.onEndTag["author"]       = (in Element e) { book.author      = e.text(); };
>         xml.onEndTag["title"]        = (in Element e) { book.title       = e.text(); };
>         xml.onEndTag["genre"]        = (in Element e) { book.genre       = e.text(); };
>         xml.onEndTag["price"]        = (in Element e) { book.price       = e.text(); };
>         xml.onEndTag["publish-date"] = (in Element e) { book.pubDate     = e.text(); };
>         xml.onEndTag["description"]  = (in Element e) { book.description = e.text(); };
>
>         xml.parse();
>
>         books ~= book;
>     };
>     xml.parse();
>
>     // Put it back together again;
>     auto doc = new Document(new Tag("catalog"));
>     foreach(book;books)
>     {
>         auto element = new Element("book");
>         element.tag.attr["id"] = book.id;
>
>         element ~= new Element("author",      book.author);
>         element ~= new Element("title",       book.title);
>         element ~= new Element("genre",       book.genre);
>         element ~= new Element("price",       book.price);
>         element ~= new Element("publish-date",book.pubDate);
>         element ~= new Element("description", book.description);
>
>         doc ~= element;
>     }
>
>     // Pretty-print it
>     //writefln(join(doc.pretty(3),"\n"));
> }
>
> ------ XML FILE ------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <books>
> 	<book id="1-23456789">
> 		<author>Count Dracula</author>
> 		<title>D for Vampires</title>
> 		<genre>Programming</genre>
> 		<price>66.6</price>
> 		<publish-date>1897</publish-date>
> 		<description>Tomb programming with D</description>
> 	</book>
> </books>

Are you sure that ldc hasn't actually just optimised away the whole of parse()?
Check to asm to be sure.
1 2 3 4