Given that 98% of the time is spent in that function, I rewrote your “get a number” function:
int Ten_To_One_Million_Ten(void)
{
unsigned Number = (((unsigned)rand() << 5) + (unsigned)rand()%32) % 1000000 + 10;
assert(Number >= 10 && Number <= 1000010);
return Number;
}
Now, on my machine, using clang++ (Version 3.7 from about 4 weeks ago) takes 0.0839 seconds according to the program’s own measurement, and 0.089s according to Linux’s time
command.
If I make X2 larger by another zero, it takes 12s to run the program, and 93% of the time is in Add_Node
, and int_malloc
ends up being 0.17% of the total execution time, and operator new
0.03%.
I’m fairly sure we can conclusively say that new
is not the problem here… (Even after my improved random function, the get-a-random-number functionality accounts for about 2% of the total execution time – in other words, the calculating of a random number takes about 10x the time of operator new
).
1
solved Linux C++ new operator incredibly slow [closed]