| 1 |
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|---|
| 2 |
|
|---|
| 3 |
/* benchmark-propagation.c - Benchmark packet propagation through elements. |
|---|
| 4 |
* |
|---|
| 5 |
* Copyright (C) 2006 Hans Petter Jansson |
|---|
| 6 |
* |
|---|
| 7 |
* This library is free software; you can redistribute it and/or |
|---|
| 8 |
* modify it under the terms of the GNU Lesser General Public |
|---|
| 9 |
* License as published by the Free Software Foundation; either |
|---|
| 10 |
* version 2 of the License, or (at your option) any later version. |
|---|
| 11 |
* |
|---|
| 12 |
* This library is distributed in the hope that it will be useful, |
|---|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 15 |
* Lesser General Public License for more details. |
|---|
| 16 |
* |
|---|
| 17 |
* You should have received a copy of the GNU Lesser General Public |
|---|
| 18 |
* License along with this library; if not, write to the |
|---|
| 19 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|---|
| 20 |
* Boston, MA 02111-1307, USA. |
|---|
| 21 |
* |
|---|
| 22 |
* Authors: Hans Petter Jansson <hpj@copyleft.no> |
|---|
| 23 |
*/ |
|---|
| 24 |
|
|---|
| 25 |
#define BENCHMARK_UNIT_NAME "propagation" |
|---|
| 26 |
|
|---|
| 27 |
#include "benchmark-common.c" |
|---|
| 28 |
|
|---|
| 29 |
#define PACKET_SIZE_DOUBLINGS 20 |
|---|
| 30 |
#define SUBTEST_SECONDS 2 |
|---|
| 31 |
#define MAX_PIPELINE_LENGTH 64 |
|---|
| 32 |
|
|---|
| 33 |
static FlowElement *elements [MAX_PIPELINE_LENGTH]; |
|---|
| 34 |
static guint packet_size; |
|---|
| 35 |
static guint pipeline_length; |
|---|
| 36 |
|
|---|
| 37 |
static void |
|---|
| 38 |
benchmark_packet_size (void) |
|---|
| 39 |
{ |
|---|
| 40 |
FlowPad *input_pad = FLOW_PAD (flow_simplex_element_get_input_pad (FLOW_SIMPLEX_ELEMENT (elements [0]))); |
|---|
| 41 |
FlowPad *output_pad = FLOW_PAD (flow_simplex_element_get_output_pad (FLOW_SIMPLEX_ELEMENT (elements [pipeline_length - 1]))); |
|---|
| 42 |
gint n_packets = 0; |
|---|
| 43 |
gpointer buf; |
|---|
| 44 |
|
|---|
| 45 |
benchmark_start_cpu_timer (SUBTEST_SECONDS); |
|---|
| 46 |
|
|---|
| 47 |
while (benchmark_is_running) |
|---|
| 48 |
{ |
|---|
| 49 |
FlowPacketQueue *packet_queue; |
|---|
| 50 |
FlowPacket *packet; |
|---|
| 51 |
|
|---|
| 52 |
buf = g_malloc0 (packet_size); |
|---|
| 53 |
packet = flow_packet_new (FLOW_PACKET_FORMAT_BUFFER, buf, packet_size); |
|---|
| 54 |
g_free (buf); |
|---|
| 55 |
|
|---|
| 56 |
flow_pad_push (input_pad, packet); |
|---|
| 57 |
|
|---|
| 58 |
packet_queue = flow_pad_get_packet_queue (output_pad); |
|---|
| 59 |
packet = flow_packet_queue_pop_packet (packet_queue); |
|---|
| 60 |
|
|---|
| 61 |
g_assert (packet != NULL); |
|---|
| 62 |
|
|---|
| 63 |
flow_packet_free (packet); |
|---|
| 64 |
n_packets++; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
#if defined (BENCHMARK_PACKET_SIZE) |
|---|
| 68 |
benchmark_add_data_point (packet_size, (gdouble) n_packets * (gdouble) packet_size / (gdouble) SUBTEST_SECONDS); |
|---|
| 69 |
#else |
|---|
| 70 |
benchmark_add_data_point (pipeline_length, (gdouble) n_packets * (gdouble) packet_size / (gdouble) SUBTEST_SECONDS); |
|---|
| 71 |
#endif |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
static void |
|---|
| 75 |
benchmark_pipeline_length (void) |
|---|
| 76 |
{ |
|---|
| 77 |
guint i; |
|---|
| 78 |
|
|---|
| 79 |
/* Set up pipeline */ |
|---|
| 80 |
|
|---|
| 81 |
for (i = 0; i < pipeline_length; i++) |
|---|
| 82 |
elements [i] = g_object_new (FLOW_TYPE_SIMPLEX_ELEMENT, NULL); |
|---|
| 83 |
|
|---|
| 84 |
for (i = 1; i < pipeline_length; i++) |
|---|
| 85 |
{ |
|---|
| 86 |
FlowOutputPad *output_pad; |
|---|
| 87 |
FlowInputPad *input_pad; |
|---|
| 88 |
|
|---|
| 89 |
output_pad = flow_simplex_element_get_output_pad (FLOW_SIMPLEX_ELEMENT (elements [i - 1])); |
|---|
| 90 |
input_pad = flow_simplex_element_get_input_pad (FLOW_SIMPLEX_ELEMENT (elements [i])); |
|---|
| 91 |
|
|---|
| 92 |
flow_pad_connect (FLOW_PAD (output_pad), FLOW_PAD (input_pad)); |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
#if defined (BENCHMARK_PACKET_SIZE) |
|---|
| 96 |
for (i = 0, packet_size = 1; i < PACKET_SIZE_DOUBLINGS; i++, packet_size <<= 1) |
|---|
| 97 |
{ |
|---|
| 98 |
benchmark_packet_size (); |
|---|
| 99 |
} |
|---|
| 100 |
#else |
|---|
| 101 |
packet_size = 1; |
|---|
| 102 |
benchmark_packet_size (); |
|---|
| 103 |
#endif |
|---|
| 104 |
|
|---|
| 105 |
for (i = 0; i < pipeline_length; i++) |
|---|
| 106 |
g_object_unref (elements [i]); |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
static void |
|---|
| 110 |
benchmark_run (void) |
|---|
| 111 |
{ |
|---|
| 112 |
gint i; |
|---|
| 113 |
|
|---|
| 114 |
benchmark_begin_data_plot ("Packet propagation", "Packet size (bytes)", "Data propagated (bytes/s)"); |
|---|
| 115 |
benchmark_begin_data_set (); |
|---|
| 116 |
|
|---|
| 117 |
for (i = 2; i < MAX_PIPELINE_LENGTH; i++) |
|---|
| 118 |
{ |
|---|
| 119 |
pipeline_length = i; |
|---|
| 120 |
benchmark_pipeline_length (); |
|---|
| 121 |
} |
|---|
| 122 |
} |
|---|