Time inserts, searches.
authorRobert Haas <[email protected]>
Wed, 25 Jul 2012 16:24:24 +0000 (12:24 -0400)
committerRobert Haas <[email protected]>
Wed, 25 Jul 2012 16:24:24 +0000 (12:24 -0400)
contrib/hashtest/hashtest.c

index 94120216a713e2547e2b11ce9046b1ffa795c46f..90cc2f1681f17cf9ace73bf2c3fe31b74e06f2da 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "funcapi.h"
 #include "miscadmin.h"
+#include "portability/instr_time.h"
 #include "storage/ipc.h"
 #include "utils/chash.h"
 
@@ -96,6 +97,11 @@ test_chash(PG_FUNCTION_ARGS)
 {
        uint32  i;
        hentry  e;
+       instr_time t0,
+                          t1,
+                          t2;
+
+       INSTR_TIME_SET_CURRENT(t0);
 
        for (i = 0; i < 1000000; ++i)
        {
@@ -111,6 +117,8 @@ test_chash(PG_FUNCTION_ARGS)
                        elog(LOG, "insert %u: worked twice", i);
        }
 
+       INSTR_TIME_SET_CURRENT(t1);
+
        for (i = 0; i < 1000000; ++i)
        {
                bool ok;
@@ -123,6 +131,14 @@ test_chash(PG_FUNCTION_ARGS)
                        elog(LOG, "search %u: found %u", i, e.val);
        }
 
+       INSTR_TIME_SET_CURRENT(t2);
+       INSTR_TIME_SUBTRACT(t2, t1);
+       INSTR_TIME_SUBTRACT(t1, t0);
+
+       elog(LOG, "inserts: %lu us; searches: %lu us",
+               (unsigned long) INSTR_TIME_GET_MICROSEC(t2),
+               (unsigned long) INSTR_TIME_GET_MICROSEC(t1));
+
        PG_RETURN_VOID();
 }
 
@@ -169,6 +185,11 @@ Datum
 test_dynahash(PG_FUNCTION_ARGS)
 {
        uint32  i;
+       instr_time t0,
+                          t1,
+                          t2;
+
+       INSTR_TIME_SET_CURRENT(t0);
 
        for (i = 0; i < 1000000; ++i)
        {
@@ -182,6 +203,8 @@ test_dynahash(PG_FUNCTION_ARGS)
                        elog(LOG, "insert %u: worked twice", i);
        }
 
+       INSTR_TIME_SET_CURRENT(t1);
+
        for (i = 0; i < 1000000; ++i)
        {
                bool    ok;
@@ -194,5 +217,13 @@ test_dynahash(PG_FUNCTION_ARGS)
                        elog(LOG, "search %u: found %u", i, val);
        }
 
+       INSTR_TIME_SET_CURRENT(t2);
+       INSTR_TIME_SUBTRACT(t2, t1);
+       INSTR_TIME_SUBTRACT(t1, t0);
+
+       elog(LOG, "inserts: %lu us; searches: %lu us",
+               (unsigned long) INSTR_TIME_GET_MICROSEC(t2),
+               (unsigned long) INSTR_TIME_GET_MICROSEC(t1));
+
        PG_RETURN_VOID();
 }