Rapideco de memordisponigo en C++ STL

Apr 12, 2008 20:56

en Having recently stumbled upon memory performance issues in a C++ program, I've just tested the effect of pool allocator with C++ STL. I did not find any benchmark out there, so I wrote a sample C++ program using a STL list and measured how fast it performed with three different allocation strategies. Let's begin using the standard allocator.
eo Havinte problemojn de memora rendimento lastatempe en C++ programo, mi ĵus testis la efikon de malsamaj memordisponigiloj per C++ STL. Mi nenie trovis takstestilon, do mi skribis specimenon de C++ programo uzante STL-liston kaj mezuris kiom rapide ĝi plenumis per tri malsamoj strategioj de memordisponigo. Ni komencu per la defaŭlta memordisponigilo.
  // Benchmark with standard allocator
  // Takstestilo per defaŭlta memordisponigilo
  #include

int main()
  {
    for (int i = 100000; i >= 0; i--) {
      std::list l;

for (int j = 1000; j >= 0; j--) {
        l.push_back(j);
      }
    }
    return 0;
  }

$ g++ -O3 test.c $ time ./a.out real 0m10.658s user 0m10.657s sys 0m0.000s en Now let's replace the default allocator with the pool allocator __pool_alloc from stdlibc++. I've highlighted in blue below the only changes required to the above program.
eo Ni nun anstataŭigas la defaŭltan memordisponigilon per __pool_alloc de stdlibc++. Mi emfazis per blua koloro ĉi-sube la nurajn ŝanĝojn el la supra programo.
  // Benchmark with __gnu_cxx::__pool_alloc
  // Takstestilo per __gnu_cxx::__pool_alloc
  #include
  #include

int main()
  {
    for (int i = 100000; i >= 0; i--) {
      std::list > l;

for (int j = 1000; j >= 0; j--) {
        l.push_back(j);
      }
    }
    return 0;
  }

$ g++ -O3 test.c $ time ./a.out real 0m6.090s user 0m6.084s sys 0m0.000s en Now let's do the same again using this time the fast_pool_allocator allocator from the boost library.
eo Ni nu faru la samon denove uzante ĉi-foje la memordispongilon fast_pool_allocator de la biblioteko boost.
  // Benchmark with boost::fast_pool_allocator
  // Takstestilo per boost::fast_pool_allocator
  #include
  #include

int main()
  {
    for (int i = 100000; i >= 0; i--) {
      std::list > l;

for (int j = 1000; j >= 0; j--) {
        l.push_back(j);
      }
    }
    return 0;
  }

$ g++ -O3 test.c $ time ./a.out real 0m4.808s user 0m4.780s sys 0m0.000s
Performance summary/Resumo de rendimento:
allocator/disponigilotime/daŭro default allocator10.658s __gnu_cxx::__pool_alloc6.090s1.75 x faster/pli rapida boost::fast_pool_allocator4.804s2.21 x faster/pli rapida
en Performance gain is quite large for such a little extra effort. Depending on the program, your mileage may of course vary.
eo Plibonigo de rendimento sufiĉe grandas por tia aldona peneto. La rezultoj povas kompreneble ŝanĝiĝi laŭ la programo.

vim, cpp

Previous post Next post
Up