U++ Core vs D programming language
BCS
BCS at pathlink.com
Thu May 1 09:10:10 PDT 2008
Jason House wrote:
> Poking around the U++ web site, I spotted this page:
> http://www.ultimatepp.org/www$uppweb$vsd$en-us.html
>
> It says "C++ is still well ahead of D (by 70%) if not being hold back by standard library design and average implementation..."
>
> Since Walter is very proud of D's strings, I wonder if this'll get any attention. They use 64 bit gdc for their speed test. I guess they're using D1 even though they link to a D2 page...
by junking most of the IO and using a table for the char type check I
speed up the program by 15% (the older program runs in 115% the time of
the new)
import std.file;
import std.stdio;
import std.date;
int main (char[][] args)
{
int w_total;
int l_total;
int c_total;
int[char[]] dictionary;
foreach(arg; args[1..$])
{
d_time start = getUTCtime();
char[] input;
int w_cnt, l_cnt, c_cnt;
int inword;
int wstart;
input = cast(char[])std.file.read(arg);
foreach(int j, char c; input)
{
if (c == '\n'){ ++l_cnt; goto skip; }
if (num[c])
{
}
else if (alph[c])
{
if (!inword)
{
wstart = j;
inword = 1;
++w_cnt;
}
}
else skip: if (inword)
{
char[] word = input[wstart .. j];
dictionary[word]++;
inword = 0;
}
++c_cnt;
}
if (inword)
{
char[] w = input[wstart .. input.length];
dictionary[w]++;
}
l_total += l_cnt;
w_total += w_cnt;
c_total += c_cnt;
auto stop = getUTCtime();
writef("%s\n", cast(float)(stop-start)/TicksPerSecond);
// avg old runtime on my box was 114
writef("%s\n\n", 144/cast(float)(stop-start));
}
writefln("%8s%8s%8s\n", l_total, w_total, c_total);
return 0;
}
int[128] num = [
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
];
int[128] alph = [
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
];
More information about the Digitalmars-d
mailing list