Optimization ???
Mattdef
mattdef at gmail.com
Thu Feb 20 15:31:35 PST 2014
Hi
Why this code is 2 times longer in D then C# ?
module hello;
import std.stdio;
import std.datetime;
import std.string;
import std.conv;
int main(string[] argv)
{
writeln("Tape \"Y\" to launch benchmark or any other touch to
exit program :");
string s = chomp(readln());
while(s == "y" || s == "Y")
{
auto bench = benchmark!(Benchmark)(1);
writefln("Execution time : %s ms", bench[0].msecs);
s = chomp(readln());
}
return 0;
}
void Benchmark()
{
uint count = 0;
student michael = null;
while (count < 1_000_000)
{
michael = new student("Michael", Date(1998, 5, 1), 12);
michael.setName("Joseph" ~ to!string(count));
count++;
}
writeln(michael.getState());
}
class student
{
private:
string _name;
Date _birthday;
int _evaluation;
public:
string getState()
{
return _name ~ "'s birthday " ~ _birthday.toSimpleString() ~ "
and his evaluation is " ~ to!string(_evaluation);
}
this(string name, Date birthday, int eval)
{
_name = name;
_birthday = birthday;
_evaluation = eval;
}
void setName(string name)
{
_name = name;
}
void setBirthday(Date birthday)
{
_birthday = birthday;
}
void setEvaluation(int eval)
{
_evaluation = eval;
}
}
More information about the Digitalmars-d-learn
mailing list