Решил поделиться результатами.
Процессор, AMD FX 8350, 4Ghz
Компиляторы:
gcc version 7.2.0 (Ubuntu 7.2.0-1ubuntu1~16.04)
Vala 0.36.8
C/C++, без try catch
const char* noexcept_thrower_c(int i)
{
if (i == 0)
return "error";
return NULL;
}
int noexcept_try(int i)
{
int res;
if (noexcept_thrower_c(i) == NULL)
{
res = 0;
}
else
{
res = 1;
}
return res;
}
void thrower_cpp(int i)
{
if (i == 0)
throw std::runtime_error("error");
}
int cpp_try(int i)
{
int res;
try
{
thrower_cpp(i);
res = 0;
}
catch(const std::exception&)
{
res = 1;
}
return res;
}
void thrower_c(int i)
{
if (i == 0)
Throw("error");
}
int cexception_try(int i)
{
int res;
CEXCEPTION_T e = CEXCEPTION_NONE;
Try
{
thrower_c(i);
res = 0;
}
Catch(e)
{
(void)e;
res = 1;
}
return res;
}
public errordomain Error
{
Thrower,
}
void thrower(int i) throws Error
{
if (i == 0)
throw new Error.Thrower ("error");
}
int vala_try(int i)
{
int res;
try
{
thrower(i);
res = 0;
}
catch(Error e)
{
(void)e;
res = 1;
}
return res;
}
vala_try 3 ns/op
vala_catch 252 ns/op
c++_try 1 ns/op
c++_catch 2382 ns/op
noexcept_try 1 ns/op
noexcept_catch 1 ns/op
сexception_try 9 ns/op
сexception_catch 25 ns/op
Добавил исходники на github: https://github.com/fsb4000/try_bench