summaryrefslogtreecommitdiffstats
path: root/test/test-client-latency.c
blob: d05747d2481462468fc994ba1949b7398761c4d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "kiro-client.h"
#include "kiro-trb.h"
#include <assert.h>


int 
main ( int argc, char *argv[] )
{
    if (argc < 3) {
        printf ("Not enough aruments. Usage: kiro-test-latency <address> <port>\n");
        return -1;
    }

    KiroClient *client = kiro_client_new ();
    KiroTrb *trb = kiro_trb_new ();

    if (-1 == kiro_client_connect (client, argv[1], argv[2])) {
        kiro_client_free (client);
        return -1;
    }

    kiro_client_sync (client);
    kiro_trb_adopt (trb, kiro_client_get_memory (client));

    GTimer *timer = g_timer_new ();
while (1) { 
    g_timer_reset (timer);
    int i = 0;
    while(i < 50000) {
        kiro_client_sync (client);
        i++;
    }

    double elapsed = g_timer_elapsed (timer, NULL);
    printf ("Average Latency: %fus\n", (elapsed/50000.)*1000*1000);
}
    g_timer_stop (timer);
    kiro_client_free (client);
    kiro_trb_free (trb);
    return 0;
}