utils/bench-packets.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 05 Sep 2006 13:18:11 +0200
changeset 54 f860e6f94787
parent 53 ae406f4957d5
child 110 9ac6d63bfe33
permissions -rw-r--r--
change indent to be 4 spaces
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
     1
/* -*-    Mode:C++; c-basic-offset:4; tab-width:4; indent-tabs-mode:f -*- */
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2006 INRIA
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 * All rights reserved.
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 * GNU General Public License for more details.
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
14
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 12
diff changeset
    21
#include "ns3/wall-clock-ms.h"
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 12
diff changeset
    22
#include "ns3/packet.h"
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 12
diff changeset
    23
#include "ns3/chunk-constant-data.h"
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 12
diff changeset
    24
#include "ns3/chunk-udp.h"
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 12
diff changeset
    25
#include "ns3/chunk-ipv4.h"
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include <iostream>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
    28
using namespace ns3;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
static void 
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
    31
benchPtrA (uint32_t n)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
{
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    33
    ChunkConstantData data = ChunkConstantData (2000, 1);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    34
    ChunkUdp udp;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    35
    ChunkIpv4 ipv4;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    37
    for (uint32_t i = 0; i < n; i++) {
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    38
        Packet p;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    39
        p.add (&data);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    40
        p.add (&udp);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    41
        p.add (&ipv4);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    42
        Packet o = p;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    43
        o.peek (&ipv4);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    44
        o.remove (&ipv4);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    45
        o.peek (&udp);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    46
        o.remove (&udp);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    47
        o.peek (&data);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    48
        o.remove (&data);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    49
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
static void 
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
    53
benchPtrB (uint32_t n)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
{
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    55
    ChunkConstantData data = ChunkConstantData (2000, 1);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    56
    ChunkUdp udp;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    57
    ChunkIpv4 ipv4;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    59
    for (uint32_t i = 0; i < n; i++) {
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    60
        Packet p;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    61
        p.add (&data);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    62
        p.add (&udp);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    63
        p.add (&ipv4);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    64
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
static void
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
    68
ptrC2 (Packet p)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
{
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    70
    ChunkConstantData data = ChunkConstantData (2000, 1);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    71
    ChunkUdp udp;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    73
    p.peek (&udp);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    74
    p.remove (&udp);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    75
    p.peek (&data);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    76
    p.remove (&data);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
static void 
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
    80
ptrC1 (Packet p)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
{
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    82
    ChunkIpv4 ipv4;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    83
    p.peek (&ipv4);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    84
    p.remove (&ipv4);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    85
    ptrC2 (p);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
static void
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
    89
benchPtrC (uint32_t n)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
{
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    91
    ChunkConstantData data = ChunkConstantData (2000, 1);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    92
    ChunkUdp udp;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    93
    ChunkIpv4 ipv4;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    95
    for (uint32_t i = 0; i < n; i++) {
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    96
        Packet p;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    97
        p.add (&data);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    98
        p.add (&udp);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
    99
        p.add (&ipv4);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   100
        ptrC1 (p);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   101
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
static void
53
ae406f4957d5 variable/method/function coding style update
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 16
diff changeset
   106
runBench (void (*bench) (uint32_t), uint32_t n, char const *name)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
{
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   108
    WallClockMs time;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   109
    time.start ();
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   110
    (*bench) (n);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   111
    unsigned long long deltaMs = time.end ();
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   112
    double ps = n;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   113
    ps *= 1000;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   114
    ps /= deltaMs;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   115
    std::cout << name<<"=" << ps << " packets/s" << std::endl;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
int main (int argc, char *argv[])
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
{
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   120
    uint32_t n = 0;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   121
    while (argc > 0) {
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   122
        if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0) {
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   123
            char const *nAscii = argv[0] + strlen ("--n=");
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   124
            n = atoi (nAscii);
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   125
        }
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   126
        argc--;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   127
        argv++;
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   128
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   130
    runBench (&benchPtrA, n, "a");
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   131
    runBench (&benchPtrB, n, "b");
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   132
    runBench (&benchPtrC, n, "c");
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
54
f860e6f94787 change indent to be 4 spaces
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 53
diff changeset
   134
    return 0;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
}