Saturday, November 21, 2009

String Compare Performance in D

A while ago I was measuring performance of string comparison in .NET. Today I played with string type in D programming language and decided to make similar tests.

D is relatively new language with some good perspectives (by the way Andrei Alexandrescu is engaged in D development).

Here is relatively simple code, that I have used to make the tests:

import std.string;
import std.date;
import std.stdio;

string cmp1 = "SomeString";
string cmp2 = "Someotherstring";
auto iters = 100000;

void test_f()
{
    for(int i = 0; i < iters; i++) { auto res = icmp(cmp1, cmp2); }
}

void test_equal()
{
    for(int i = 0; i < iters; i++) { auto res = cmp1 == cmp2; }
}

void main()
{
    ulong[] results;
    int mean1 = 0;
    int mean2 = 0;
 
    for(int i = 0; i < 5; i++)
    {
        results = benchmark!(test_f, test_equal)(1, results);
 mean1 += results[0];
 mean2 += results[1];
 writefln("Test_f: %d", results[0]);
 writefln("Test_equal: %d", results[1]);
    }
 
    mean1 = mean1 / 5;
    mean2 = mean2 / 5;
 
    writefln("Mean Test_f: %d", mean1);
    writefln("Mean Test_equal %d", mean2);
}
Test results where interesting:
Test_f: 21
Test_equal: 2
Test_f: 21
Test_equal: 2
Test_f: 22
Test_equal: 2
Test_f: 14
Test_equal: 1
Test_f: 12
Test_equal: 1
Mean Test_f: 18
Mean Test_equal 1
18 millis for 100000 iterations looks pretty nice. It is faster then .NET string case insensitive ordinal string comparison. If you remember: .NET version completed in about 26 milliseconds. Second test function just compares two values for equality, I assume that mere pointer compare is made.

I have decided to give this relatively new language a try, it is highly possible that there will be more posts about D in this blog :).

1 comment:

  1. Hi !.
    You re, I guess , perhaps very interested to know how one can collect a huge starting capital .
    There is no need to invest much at first. You may commense to receive yields with as small sum of money as 20-100 dollars.

    AimTrust is what you thought of all the time
    AimTrust incorporates an offshore structure with advanced asset management technologies in production and delivery of pipes for oil and gas.

    It is based in Panama with affiliates around the world.
    Do you want to become an affluent person?
    That`s your chance That`s what you wish in the long run!

    I`m happy and lucky, I began to get real money with the help of this company,
    and I invite you to do the same. It`s all about how to select a correct companion who uses your funds in a right way - that`s it!.
    I take now up to 2G every day, and what I started with was a funny sum of 500 bucks!
    It`s easy to join , just click this link http://nowazygeku.o-f.com/usisotur.html
    and go! Let`s take this option together to get rid of nastiness of the life

    ReplyDelete