Comment

Comment by falcolas

Linked lists have more consistent performance than std::vector. And taking half a second to render one frame when you're averaging 100fps is way worse than consistent 50 FPS.

There was recently an article about intrusive linked lists, and this same question came up. I took the unreal linked list library, and wrote a similar std::vector implementation, and tested it. The test was simple, fire 50,000 bullets at a rate of 500 rounds per second, and remove them when they fall 2 meters. They existed in 3 separate lists: physics objects, renderable objects, and all objects. When they hit the ground, they were removed from all lists. Capture the clock ticks to generate each "frame", and do a few calculations on them at the end.

The average and median operation times for std::vector were indeed a fair bit faster (at -o3, at no optimizations the ILL implementation was faster). However, the worst case for std::vector was... much worse. More than 1000x worse in some runs. One test run showed the worse case taking over two millisecond for a single frame of just manipulating vectors!

    $ ./benchmark_ill
    Minimum: 0.000000
    Maximum: 0.000094
    Average: 0.000005
    Median: 0.000005
    Total Frames Rendered: 18968118
    Total Run Time: 100.663895

    $ ./benchmark_v
    Minimum: 0.000000
    Maximum: 0.004813
    Average: 0.000002
    Median: 0.000002
    Total Frames Rendered: 35859663
    Total Run Time: 100.664009
parent falcolas 11 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton