Slower than Python

Steven Schveighoffer schveiguy at yahoo.com
Fri Mar 1 14:31:23 PST 2013


On Fri, 01 Mar 2013 16:28:08 -0500, cvk012c  
<cvk012c at motorolasolutions.com> wrote:

> On my hardware with -inline options it now takes about 15 secs which is  
> still slower than Python but with both -inline and -noboundscheck it  
> takes 13 secs and finally beats Python.
> But I still kind of disappointed because I expected a much better  
> performance boost and got only 7%. Counting that Python is not the  
> fastest scripting language I think that similar Perl and Java scripts  
> will outperform D easily.
> Thanks Andrei and simendsjo for a quick response though.

Phobos kind of refuses to treat strings like arrays of characters, it  
insists on decoding.

With DMD and a hand-written splitter, it takes 6 seconds instead of 10 on  
my system (64-bit macosx).

struct MySplitter
{
     private string s;
     private string source;
     this(string src)
     {
         source = src;
         popFront();
     }

     @property string front()
     {
         return s;
     }

     @property bool empty()
     {
         return s.ptr == null;
     }

     void popFront()
     {
         s = source;
         if(!source.length)
         {
             source = null;
         }
         else
         {
             size_t i = 0;
             bool found = false;
             for(; i + 1 < source.length; i++)
             {
                 if(source[i] == '\r' && source[i + 1] == '\n')
                 {
                     found = true;
                     break;
                 }
             }
             s = source[0..i];
             if(found)
                 source = source[i + 2..$];
             else
                 source = source[$..$];
         }
     }
}

I'm sure splitter could be optimized to do the same thing I'm doing.

Probably can reduce that a bit using pointers instead of strings.

-Steve


More information about the Digitalmars-d mailing list