From 768aa90a002a46b8f71157b909a68f845585416a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 7 Jun 2017 19:45:14 +0200 Subject: first commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- bench.c | 107 +++++ graph.svg | 1466 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plot | 45 ++ 3 files changed, 1618 insertions(+) create mode 100644 bench.c create mode 100644 graph.svg create mode 100755 plot diff --git a/bench.c b/bench.c new file mode 100644 index 0000000..8e0f091 --- /dev/null +++ b/bench.c @@ -0,0 +1,107 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define N 100000 + + +static void +print_dur(struct timespec *start, struct timespec *end, int nlog, const char *sys) +{ + end->tv_sec -= start->tv_sec; + if ((end->tv_nsec -= start->tv_nsec) < 0) { + end->tv_sec -= 1; + end->tv_nsec += 1000000000L; + } + printf("%-10s 1<<%i %li.%09li\n", sys, nlog, end->tv_sec, end->tv_nsec); + fflush(stdout); +} + + +int +main(void) +{ + char *buf = malloc(1 << 25); + int i, nlog; + int rw[2]; + size_t n, p; + ssize_t r; + struct timespec start, end; + struct iovec iov; + + memset(buf, 0, 1 << 25); + + for (nlog = 0; nlog <= 25; nlog++) { + n = 1 << nlog; + + socketpair(PF_UNIX, SOCK_STREAM, 0, rw); + if (!fork()) { + close(rw[1]); + while (read(rw[0], buf, n) > 0); + exit(0); + } else { + close(rw[0]); + clock_gettime(CLOCK_MONOTONIC, &start); + for (i = 0; i < N; i++) + for (p = 0; p < n; p += (size_t)r) + if ((r = write(rw[1], buf + p, n - p)) < 0) + return perror("write "), 1; + close(rw[1]); + wait(NULL); + clock_gettime(CLOCK_MONOTONIC, &end); + print_dur(&start, &end, nlog, "socketpair"); + } + + pipe(rw); + if (!fork()) { + close(rw[1]); + while (read(rw[0], buf, n) > 0); + exit(0); + } else { + close(rw[0]); + clock_gettime(CLOCK_MONOTONIC, &start); + for (i = 0; i < N; i++) + for (p = 0; p < n; p += (size_t)r) + if ((r = write(rw[1], buf + p, n - p)) < 0) + return perror("write "), 1; + close(rw[1]); + wait(NULL); + clock_gettime(CLOCK_MONOTONIC, &end); + print_dur(&start, &end, nlog, "pipe"); + } + + pipe(rw); + if (!fork()) { + close(rw[1]); + while (read(rw[0], buf, n) > 0); + exit(0); + } else { + close(rw[0]); + clock_gettime(CLOCK_MONOTONIC, &start); + for (i = 0; i < N; i++) { + iov.iov_base = buf; + iov.iov_len = n; + for (p = 0; p < n; p += (size_t)r) { + r = vmsplice(rw[1], &iov, 1, 0); + if (r < 0) + return perror("vmsplice "), 1; + iov.iov_base += r; + iov.iov_len -= (size_t)r; + } + } + close(rw[1]); + wait(NULL); + clock_gettime(CLOCK_MONOTONIC, &end); + print_dur(&start, &end, nlog, "vmsplice"); + } + } + return 0; +} diff --git a/graph.svg b/graph.svg new file mode 100644 index 0000000..28ad698 --- /dev/null +++ b/graph.svg @@ -0,0 +1,1466 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plot b/plot new file mode 100755 index 0000000..97bf34c --- /dev/null +++ b/plot @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +import sys, math +import matplotlib.pyplot as plot + +#plot.xkcd() +fig = plot.figure(figsize = (3 * 2, 4 * 2)) +data = sys.stdin.read().split('\n') + +graphs = {} +points = set() +values = set() + +for line in data: + if line == '': + continue + while ' ' in line: + line = line.replace(' ', ' ') + [label, point, time] = line.split(' ') + [_, point] = point.split('<<') + point = int(point) + time = float(time) / 10 + if label not in graphs: + graphs[label] = {} + graphs[label][point] = time + points.add(point) + values.add(time) + +points = sorted(list(points)) +values = sorted(list(values)) + +for label in sorted(graphs.keys()): + graph_values = list(map(lambda x : x[1], sorted(graphs[label].items(), key = lambda x : x[0]))) + plot.plot(points, graph_values, label = label) + +plot.xticks(points, map(str, points)) +fig.suptitle('pipe(7) versus unix(7)') +plot.ylabel('millisecond') +plot.xlabel('log₂(n)') +plot.grid(axis = 'x', linestyle = ' ') +plot.legend(loc = 'upper left') +plot.xlim((min(points), max(points))) +plot.ylim((min(values) * 1.05, max(values) * 1.05)) +plot.grid(True) +plot.savefig('graph.svg', transparent = False, format = 'svg') -- cgit v1.2.3-70-g09d2