Re: [sigc] RE: libsigc++ and benchmark



Hi Jimen!

I'm using the attached "benchmark" for performance tests
when I'm working on libsigc++2. It's easy to backport it
to libsigc++-1.2 and it should also be reasonably straight
forward to port it to Qt.

(The file is not in cvs because
 1) It uses glibmm
 2) I don't know how to write a real benchmark with 100%
reproducable results.)

Regards,

  Martin


Am 2003.10.09 09:16 schrieb(en) Murray Cumming Comneon com:
Please use the mailing list.

Karl Nelson did those test so you might want to contact him directly
if you
do not get a response on the mailing list

Murray Cumming
www.murrayc.com
murrayc usa net

> From: Jimen Ching [mailto:jching flex com]
> I was going through the libsigc++ website and found the
> benchmark link. But I don't see the code used in the
> benchmark.  Is that available?  I would like to re-run it
> using the latest code from both libsigc++ and QT.
>
> Thanks in advance for any info.
>
> --jc
> --
> Jimen Ching (WH6BRR)      jching flex com     wh6brr uhm ampr org
>
_______________________________________________
libsigc-list mailing list
libsigc-list gnome org
http://mail.gnome.org/mailman/listinfo/libsigc-list
#include <iostream>
#include "../sigc++/signal.h"
#include <sigc++/functors/mem_fun.h>
#include <glibmm/timeval.h>

using namespace std;
using namespace sigc;
using namespace sigc::functor;

struct foo : public trackable
{
  int bar(int a);
  int c;
};

int foo::bar(int a)
{
  int b = c;
  c = a;
  return b;
}

int main()
{
  Glib::TimeVal t1, t2;

  foo foobar1, foobar2, foobar3, foobar4, foobar5;
  closure<int,int> slot;
  signal<int,int> emitter;
  signal<int,int>::iterator it;


  // slot benchmark ...

  slot = mem_fun(&foobar1, &foo::bar);

  t1.assign_current_time();

  for (int i=0; i < 5000; ++i)
    slot(i);

  t2.assign_current_time();
  t2.subtract(t1);

  cout << "elapsed time for calling a slot 5000 times: " << t2.tv_sec << "s " << t2.tv_usec << "us" << endl;


  // emission benchmark (zero slots) ...

  t1.assign_current_time();

  for (int i=0; i < 1000; ++i)
    emitter(i);

  t2.assign_current_time();
  t2.subtract(t1);

  cout << "elapsed time for 1000 emissions (0 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << endl;


  // emission benchmark (one slot) ...

  emitter.connect(mem_fun(&foobar1, &foo::bar));

  t1.assign_current_time();

  for (int i=0; i < 1000; ++i)
    emitter(i);

  t2.assign_current_time();
  t2.subtract(t1);

  cout << "elapsed time for 1000 emissions (1 slot): " << t2.tv_sec << "s " << t2.tv_usec << "us" << endl;


  // emission benchmark (five slot) ...

  emitter.connect(mem_fun(&foobar2, &foo::bar));
  emitter.connect(mem_fun(&foobar3, &foo::bar));
  emitter.connect(mem_fun(&foobar4, &foo::bar));
  emitter.connect(mem_fun(&foobar5, &foo::bar));

  t1.assign_current_time();

  for (int i=0; i < 1000; ++i)
    emitter(i);

  t2.assign_current_time();
  t2.subtract(t1);

  cout << "elapsed time for 1000 emissions (5 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << endl;


  // connection / disconnection benchmark ...

  emitter.clear();

  t1.assign_current_time();

  for (int i=0; i < 1000; ++i)
    {
      it = emitter.connect(mem_fun(&foobar1, &foo::bar));
      it->disconnect();
    }

  t2.assign_current_time();
  t2.subtract(t1);

  cout << "elapsed time for 1000 connections/disconnections: " << t2.tv_sec << "s " << t2.tv_usec << "us" << endl;

}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]