#include <gst/gst.h>

#undef USE_ITERATOR

#define ROUNDS 10000

#ifdef USE_ITERATOR

static void
iterator_func (const GValue * item, gpointer user_data)
{
  (void) g_value_get_object (item);
}

#else

static gboolean
plugin_filter (GstPlugin * plugin, gpointer data)
{
  return FALSE;
}

static gboolean
feature_filter (GstPluginFeature * feature, gpointer data)
{
  return FALSE;
}

#endif

gint
main (gint argc, gchar * argv[])
{
  GstClockTime t0, t1, t2, d1, d2;
  GstRegistry *registry;
  gint i;

  gst_init (&argc, &argv);

  registry = gst_registry_get ();

  t0 = gst_util_get_timestamp ();

  for (i = 0; i < ROUNDS; ++i) {
#ifdef USE_ITERATOR
    {
      GstIterator *it;
      it = gst_registry_iterate_plugins (registry);
      gst_iterator_foreach (it, iterator_func, NULL);
      gst_iterator_free (it);
    }
#else
    {
      gst_registry_plugin_filter (registry, plugin_filter, FALSE, NULL);
    }
#endif
  }

  t1 = gst_util_get_timestamp ();

  for (i = 0; i < ROUNDS; ++i) {
#ifdef USE_ITERATOR
    {
      GstIterator *it;
      it = gst_registry_iterate_features (registry);
      gst_iterator_foreach (it, iterator_func, NULL);
      gst_iterator_free (it);
    }
#else
    {
      gst_registry_feature_filter (registry, feature_filter, FALSE, NULL);
    }
#endif
  }

  t2 = gst_util_get_timestamp ();

  d1 = (t1 - t0) / ROUNDS;
  d2 = (t2 - t1) / ROUNDS;

  g_print ("plugin  filter : %.0fus\n", (gdouble) d1 / GST_USECOND);
  g_print ("feature filter : %.0fus\n", (gdouble) d2 / GST_USECOND);

  return 0;
}
