How to accelerate this program?
Lionello Lunesu
lio at remove.lunesu.com
Tue Apr 4 04:16:37 PDT 2006
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.
But why the sort?? Try this instead:
#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