VB
Size: a a a
VB
VB
f
Cxx ops ............................ 7.758 ms 8.208 ms - среднее 8.208
Nim ops ............................ 7.415 ms 7.844 ms - среднее 7.844
f
VB
qmaster$ ./a.out
min: 7.197ms, mean: 7.839ms (607 runs, 1 loops each)
VB
VB
VB
C++
#include "test.hpp"
#include <vector>
#include <random>
#include <algorithm>
#include <string>
#include "timeit.hpp"
const int Nb_Instructions = 1000000;
enum {
OPINC, OPDEC, OPMUL2, OPDIV2, OPADD7, OPNEG
};
std::random_device rd; //Will be used to obtain a seed for the random number engine
std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
std::uniform_int_distribution<> distrib(OPINC, OPNEG);
Opc* genOp() {
switch(distrib(gen)) {
case OPINC:
return new OpcInc();
case OPDEC:
return new OpcDec();
case OPMUL2:
return new OpcMul2();
case OPDIV2:
return new OpcDiv2();
case OPADD7:
return new OpcAdd7();
case OPNEG:
return new OpcNeg();
};
}
int main(void) {
std::vector<Opc*> vecOps;
//vecOps.reserve(Nb_Instructions);
for(int x = 0; x < Nb_Instructions; ++x) {
vecOps.push_back(genOp());
}
timeit([&] {
int result = 100;
for(auto op: vecOps) {
op->eval(&result);
}}, 607
);
}
VB
VB
VB
f
T&
функции. Хотя может быть это можно сделать через какой-то хак с importcpp
f
VB
VB
VB
f
name ............................... min time avg time std dv runs
Cxx ops ........................... 10.475 ms 10.691 ms ±0.211 x465
Nim ops ........................... 10.993 ms 11.212 ms ±0.222 x444
Nim ops val ....................... 10.571 ms 10.752 ms ±0.209 x461
Nim manual vtable ................. 10.368 ms 10.573 ms ±0.213 x471
Nim proc table .................... 10.559 ms 10.761 ms ±0.189 x462
Nim methods ........................ 9.370 ms 9.606 ms ±0.267 x515
f
f