D's exception cost (happy path) is large than G++
redsea
redsea at 163.com
Thu Sep 6 23:51:50 PDT 2007
D 1.018
loop 8G times, without try/catch
real 0m24.452s
user 0m23.911s
sys 0m0.005s
loop 8G times, with try/catch
real 0m31.455s
user 0m30.749s
sys 0m0.008s
add 28.6% cost
----------------
g++ (gcc version 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)
loop 8G times, without try/catch
real 0m20.971s
user 0m20.623s
sys 0m0.004s
loop 8G times, with try/catch
real 0m24.481s
user 0m23.949s
sys 0m0.004s
add 16.7% cost
-------------------
D's cost is larger.
-------------------
code:
D:
module test;
import tango.io.Stdout;
int turn=0;
int count;
void fooFunc()
{
++ count;
};
alias void function() foo_t;
void test(int c1, int c2, foo_t foo)
{
for (int j=0;j<c1;j++)
{
++ turn;
count = 0;
for (int i=0;i<c2;i++)
{
try
{
foo();
}
catch (Exception e)
{
}
}
}
Stdout("\nturn ")(turn)(" count ")(count);
}
int main()
{
test(8*1024, 1048576, &fooFunc);
return 0;
}
compile with -O -release -inline
no catch version, comment the try & catch line
-------------------
code:
c++
#include <stdio.h>
#include <exception>
volatile int turn=0;
volatile int count;
void fooFunc(void)
{
++ count;
};
typedef void (*foo_t)(void);
void test(int c1, int c2, foo_t foo)
{
for (int j=0;j<c1;j++)
{
++ turn;
count = 0;
for (int i=0;i<c2;i++)
{
try
{
foo();
}
catch (std::exception &e)
{
}
}
}
printf("\nturn %d, count %d", turn, count);
}
int main()
{
test(8*1024, 1048576, fooFunc);
return 0;
}
compile with -O2
no catch version, comment the try & catch line
More information about the Digitalmars-d
mailing list