activesys/libcstl — Issue #11: libcstl效率问题
Author: activesys
Created: 2012-02-20 14:25:55+00:00
State: open

[wb@ActiveSys libcstl]$ cat test_cpp_stl.cpp
#include

void test_cpp_stl(void)
{
std::vector v1, v2;

v1.assign(300, -39);
v2 = v1;
}

int main(int argc, char* argv[])
{
for (int i = 0; i < 100000; ++i) {
test_cpp_stl();
}
return 0;
}

[wb@ActiveSys libcstl]$ cat test_cstl.c
#include

void test_cstl(void)
{
vector_t* pvec1 = NULL;
vector_t* pvec2 = NULL;

if ((pvec1 = create_vector(int)) == NULL) {
return;
}
if ((pvec2 = create_vector(int)) == NULL) {
return;
}

vector_init_elem(pvec1, 300, -39);
vector_init(pvec2);
vector_assign(pvec2, pvec1);

vector_destroy(pvec1);
vector_destroy(pvec2);
}

int main(int argc, char* argv[])
{
int i = 0;
for (i = 0; i < 100000; ++i) {
test_cstl();
}
return 0;
}

[wb@ActiveSys libcstl]$ time ./test_cpp_stl

real 0m0.342s
user 0m0.303s
sys 0m0.021s
[wb@ActiveSys libcstl]$ time ./test_cstl

real 0m44.984s
user 0m42.134s
sys 0m0.039s