How to accelerate this program?

Dave Dave_member at pathlink.com
Tue Apr 4 07:46:46 PDT 2006


In article <e0tkil$kkn$1 at digitaldaemon.com>, Lionello Lunesu says...
>
>Dave wrote:
>> From what I've seen, the bottleneck is probably in I/O. Use BufferedFile and a
>> buffer for each readline. 
>
>C's FILE and fopen also create a buffered stream, so I doubt that will 
>make a difference.

Yea, but it does make about a 15% difference (with readLine(bufr) faster). I/O
is definately not the bottleneck though - my test data was screwed up in that it
was only doing 4 AA inserts, which is the actual bottleneck.

>
>But why the sort?? Try this instead:

You're right that is not needed. I saw the sort in the C++ version (but didn't
look closely enough at what it was doing).

>
>#import std.stdio;
>#import std.perf;
>#import std.stream;
>#
>#int main(char[][] argv)
>#{
>#	if (argv.length < 3)
>#	{
>#		writefln("Wrong arguments");
>#		return 1;
>#	}
>#
>#	char[8192] bufr;
>#	int[char[]] emails;
>#	char[] email;
>#
>#	PerformanceCounter counter = new PerformanceCounter();
>#	counter.start();
>#
>#	BufferedFile bsi = new BufferedFile(argv[1]);
>#	BufferedFile bso = new BufferedFile(argv[2],FileMode.Out);
>#	while(!bsi.eof)
>#	{
>#		email = bsi.readLine(bufr); // bufr is key to perf.
>#		if (!(email in emails))
>#		{
>#			emails[email.dup] = 0; // Note .dup
>#			bso.writeLine(email);
>#		}
>#	}
>#	bso.close;
>#	bsi.close;
>#
>#	counter.stop();
>#	writefln(counter.milliseconds());
>#
>#	return 0;
>#}





More information about the Digitalmars-d mailing list