Replacing tango.text.Ascii.isearch

rassoc rassoc at posteo.de
Sat Oct 8 01:07:46 UTC 2022


On 10/8/22 00:50, Siarhei Siamashka via Digitalmars-d-learn wrote:
> On Friday, 7 October 2022 at 12:19:59 UTC, bachmeier wrote:
> python -c "print(('a' * 49 + 'b') * 20000)" > test.lst

That's generating a file with a single line:

$> wc -l test.lst
1 test.lst

Going with an appropriate 100k mixed line file and your mentioned needle, D is still quite a bit slower, but the results aren't as drastic and nowhere near "two orders of magnitude".

$> crystal build --release -o search-cr search.cr
abort "Need a needle argument." unless ARGV.size >= 1
needle = ARGV[0].downcase
puts File.open("words.txt").each_line.count(&.downcase.includes? needle)

$> ldc2 -O2 --release -of search-ldc search.d
import std;
void main(string[] args) {
     enforce(args.length > 1, "Need a needle argument.");
     auto needle = args[1].toLower;
     File("words.txt").byLine.count!(ln => ln.asLowerCase.canFind(needle)).writeln;
}


More information about the Digitalmars-d-learn mailing list