# HG changeset patch # User Matthew Wild # Date 1290087945 0 # Node ID 05b2fd8fe5aac8c2dac372619ab95adfa4500538 # Parent cfb60868c7458d7b95f1404edaa96234c58b7c5f Commit latest code diff -r cfb60868c745 -r 05b2fd8fe5aa build --- a/build Fri May 15 22:12:22 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -gcc -g -O3 main.c $@ -I /home/matthew/Development/strophe/trunk/libstrophe /home/matthew/Development/strophe/trunk/libstrophe/libexpat.a /home/matthew/Development/strophe/trunk/libstrophe/libstrophe.a -lresolv -lexpat -o bench - diff -r cfb60868c745 -r 05b2fd8fe5aa main.c --- a/main.c Fri May 15 22:12:22 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,159 +0,0 @@ -#include -#include -#include -#include - -#include - - -xmpp_conn_t *conn1, *conn2; - -unsigned long mincount, maxcount; -unsigned long count = 0; - -unsigned long sum_squares = 0; -unsigned long samples = 0; /* Current number of samples taken */ -unsigned long max_samples = 15; /* The number of samples to do, if specified by user */ - -time_t lasttime; /* Time of the last sample we took */ - -char* jid1 = "test1@getjabber.ath.cx"; -char* jid2 = "test2@getjabber.ath.cx"; -char* pass1 = "test1"; -char* pass2 = "test2"; - -xmpp_stanza_t *bstanza; - -int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) -{ - xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; - - if(!xmpp_stanza_get_child_by_name(stanza, "body")) return 1; - if(!strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error")) return 1; - - if(conn == conn2) - { - count++; - if(time(NULL) != lasttime) - { - - if(lasttime > 0) - { - //printf("%d stanzas/sec\n", count); - if(count > maxcount && lasttime > 0) - { - //printf("%d beats old maximum of %d\n", count, maxcount); - maxcount = count; - } - sum_squares += count*count; - samples++; - if(samples >= max_samples) - { - printf("%Lf\n", sqrtl(sum_squares/samples)); - exit(0); - } - } - count = 0; - lasttime = time(NULL); - } - xmpp_send(conn1, bstanza); - } - - return 1; -} - -/* define a handler for connection events */ -void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, - const int error, xmpp_stream_error_t * const stream_error, - void * const userdata) -{ - xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; - - if (status == XMPP_CONN_CONNECT) { - xmpp_stanza_t* pres; - //fprintf(stderr, "DEBUG: connected\n"); - xmpp_handler_add(conn,message_handler, NULL, "message", NULL, ctx); - - /* Send initial so that we appear online to contacts */ - pres = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(pres, "presence"); - xmpp_send(conn, pres); - xmpp_stanza_release(pres); - - if(conn == conn2) - { - count = 0; - lasttime = 0; - - xmpp_send(conn1, bstanza); - } - } - else { - //fprintf(stderr, "DEBUG: disconnected\n"); - xmpp_stop(ctx); - } -} - -int main(int argc, char *argv[]) -{ - xmpp_ctx_t *ctx; - xmpp_log_t *log = NULL; - xmpp_stanza_t *body, *text; - - //printf("Loading...\n"); - /* init library */ - xmpp_initialize(); - - /* create a context */ -#ifdef LOGGING - log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); /* pass NULL instead to silence output */ -#endif - ctx = xmpp_ctx_new(NULL, log); - - /* create a connection */ - conn1 = xmpp_conn_new(ctx); - conn2 = xmpp_conn_new(ctx); - - /* setup authentication information */ - xmpp_conn_set_jid(conn1, jid1); - xmpp_conn_set_pass(conn1, pass1); - - xmpp_conn_set_jid(conn2, jid2); - xmpp_conn_set_pass(conn2, pass2); - - - bstanza = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(bstanza, "message"); - xmpp_stanza_set_type(bstanza, "chat"); - xmpp_stanza_set_attribute(bstanza, "to", jid2); - - body = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(body, "body"); - - text = xmpp_stanza_new(ctx); - xmpp_stanza_set_text(text, "Hello"); - xmpp_stanza_add_child(body, text); - xmpp_stanza_add_child(bstanza, body); - - xmpp_stanza_release(text); - xmpp_stanza_release(body); - - /* initiate connection */ - xmpp_connect_client(conn1, "localhost", 5222, conn_handler, ctx); - xmpp_connect_client(conn2, "localhost", 5222, conn_handler, ctx); - - //printf("Connecting...\n"); - /* enter the event loop - - our connect handler will trigger an exit */ - xmpp_run(ctx); - - /* release our connection and context */ - xmpp_conn_release(conn1); - xmpp_conn_release(conn2); - xmpp_ctx_free(ctx); - - /* final shutdown of the library */ - xmpp_shutdown(); - - return 0; -} diff -r cfb60868c745 -r 05b2fd8fe5aa throughput/build --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/throughput/build Thu Nov 18 13:45:45 2010 +0000 @@ -0,0 +1,2 @@ +gcc -g -O3 main.c $@ -I /home/matthew/Development/strophe/trunk/libstrophe /home/matthew/Development/strophe/trunk/libstrophe/libexpat.a /home/matthew/Development/strophe/trunk/libstrophe/libstrophe.a -lresolv -lexpat -o bench2 + diff -r cfb60868c745 -r 05b2fd8fe5aa throughput/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/throughput/main.c Thu Nov 18 13:45:45 2010 +0000 @@ -0,0 +1,165 @@ +#include +#include +#include +#include + +#include + + +xmpp_conn_t *conn1, *conn2; + +unsigned long mincount, maxcount; +unsigned long count = 0; + +unsigned long sum_squares = 0; +unsigned long samples = 0; /* Current number of samples taken */ +unsigned long discard_samples = 5; +unsigned long max_samples = 20; /* The number of samples to do, if specified by user */ + +time_t lasttime; /* Time of the last sample we took */ + +char* jid1 = "test1@getjabber.ath.cx"; +char* jid2 = "test2@getjabber.ath.cx"; +char* pass1 = "test1"; +char* pass2 = "test2"; + +xmpp_stanza_t *bstanza; + +int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) +{ + xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; + + if(!xmpp_stanza_get_child_by_name(stanza, "body")) return 1; + if(!strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error")) return 1; + + if(conn == conn2) + { + count++; + if(time(NULL) != lasttime) + { + if(lasttime > 0) + { + printf("%ld stanzas/sec\n", count); + if(count > maxcount) + { + printf("%ld beats old maximum of %ld\n", count, maxcount); + maxcount = count; + } + if(samples >= discard_samples) + sum_squares += count*count; + samples++; + if(samples >= max_samples) + { + printf("----\nMax: %ld\nRMS: %.2Lf\n----\n", + maxcount, + sqrtl(sum_squares/(samples-discard_samples)) + ); + xmpp_stop(ctx); + return 0; + } + } + count = 0; + lasttime = time(NULL); + } + xmpp_send(conn1, bstanza); + //fprintf(stderr, "C: %d\n", count); + } + + return 1; +} + +/* define a handler for connection events */ +void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, + const int error, xmpp_stream_error_t * const stream_error, + void * const userdata) +{ + xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; + + if (status == XMPP_CONN_CONNECT) { + xmpp_stanza_t* pres; + fprintf(stderr, "DEBUG: connected\n"); + xmpp_handler_add(conn,message_handler, NULL, "message", NULL, ctx); + + /* Send initial so that we appear online to contacts */ + pres = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(pres, "presence"); + xmpp_send(conn, pres); + xmpp_stanza_release(pres); + + if(conn == conn2) + { + count = 0; + lasttime = 0; + + xmpp_send(conn1, bstanza); + } + } + else { + fprintf(stderr, "DEBUG: disconnected\n"); + xmpp_stop(ctx); + } +} + +int main(int argc, char *argv[]) +{ + xmpp_ctx_t *ctx; + xmpp_log_t *log = NULL; + xmpp_stanza_t *body, *text; + + printf("Loading...\n"); + /* init library */ + xmpp_initialize(); + + /* create a context */ +#ifdef LOGGING + log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); /* pass NULL instead to silence output */ +#endif + ctx = xmpp_ctx_new(NULL, log); + + /* create a connection */ + conn1 = xmpp_conn_new(ctx); + conn2 = xmpp_conn_new(ctx); + + /* setup authentication information */ + xmpp_conn_set_jid(conn1, jid1); + xmpp_conn_set_pass(conn1, pass1); + + xmpp_conn_set_jid(conn2, jid2); + xmpp_conn_set_pass(conn2, pass2); + + + bstanza = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(bstanza, "message"); + xmpp_stanza_set_type(bstanza, "chat"); + xmpp_stanza_set_attribute(bstanza, "to", jid2); + + body = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(body, "body"); + + text = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(text, "Hello"); + xmpp_stanza_add_child(body, text); + xmpp_stanza_add_child(bstanza, body); + + xmpp_stanza_release(text); + xmpp_stanza_release(body); + + /* initiate connection */ + xmpp_connect_client(conn1, "localhost", 5222, conn_handler, ctx); + xmpp_connect_client(conn2, "localhost", 5222, conn_handler, ctx); + + printf("Connecting...\n"); + /* enter the event loop - + our connect handler will trigger an exit */ + xmpp_run(ctx); + + /* release our connection and context */ + xmpp_conn_release(conn1); + xmpp_conn_release(conn2); + xmpp_ctx_free(ctx); + + /* final shutdown of the library */ + xmpp_shutdown(); + + return 0; +}