From 29bf2197fb61f60eb611e093a9e60245b61941c3 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Wed, 15 Apr 2020 10:20:48 +0300 Subject: [PATCH] Convert the benchmark setup to FPS-based --- benchmarks/benchmark.pl | 32 ++++++++++++-------------------- benchmarks/ffmpeg/sender.cc | 8 ++++---- benchmarks/kvzrtp/sender.cc | 9 ++++----- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/benchmarks/benchmark.pl b/benchmarks/benchmark.pl index 7586dc9..f72432d 100755 --- a/benchmarks/benchmark.pl +++ b/benchmarks/benchmark.pl @@ -9,7 +9,7 @@ use Getopt::Long; $| = 1; # autoflush sub send_benchmark { - my ($lib, $addr, $port, $iter, $threads, $start, $end, $step) = @_; + my ($lib, $addr, $port, $iter, $threads, $start, $end) = @_; my ($socket, $remote, $data); $socket = IO::Socket::INET->new( @@ -23,8 +23,8 @@ sub send_benchmark { $remote = $socket->accept(); while ($threads ne 0) { - for (my $i = $start; $i <= $end; $i += $step) { - my $logname = "send_results_$threads" . "threads_$i". "us"; + for (my $i = $start; $i <= $end; $i *= 2) { + my $logname = "send_results_$threads" . "threads_$i". "fps"; for ((1 .. $iter)) { $remote->recv($data, 16); system ("time ./$lib/sender $threads $i >> $lib/results/$logname 2>&1"); @@ -36,7 +36,7 @@ sub send_benchmark { } sub recv_benchmark { - my ($lib, $addr, $port, $iter, $threads, $start, $end, $step) = @_; + my ($lib, $addr, $port, $iter, $threads, $start, $end) = @_; my $socket = IO::Socket::INET->new( PeerAddr => $addr, @@ -47,8 +47,8 @@ sub recv_benchmark { ) or die "Couldn't connect to $addr:$port : $@\n"; while ($threads ne 0) { - for (my $i = $start; $i <= $end; $i += $step) { - my $logname = "recv_results_$threads" . "threads_$i". "us"; + for (my $i = $start; $i <= $end; $i *= 2) { + my $logname = "recv_results_$threads" . "threads_$i". "fps"; for ((1 .. $iter)) { $socket->send("start"); system ("time ./$lib/receiver $threads >> $lib/results/$logname 2>&1"); @@ -65,25 +65,17 @@ GetOptions( "addr=s" => \(my $addr = ""), "port=i" => \(my $port = 0), "iter=i" => \(my $iter = 100), - "sleep=i" => \(my $sleep = 0), "threads=i" => \(my $threads = 1), - "start=i" => \(my $start = 0), - "end=i" => \(my $end = 0), - "step=i" => \(my $step = 0) + "start=f" => \(my $start = 0), + "end=f" => \(my $end = 0), ) or die "failed to parse command line!\n"; if ($lib eq "") { print "library not defined!\n" and exit; } -if ($sleep ne 0) { - if ($start ne 0 or $end ne 0 or $step ne 0) { - print "start/end/step and sleep are mutually exclusive\n" and exit; - } - - $start = $sleep; - $end = $sleep + 1; - $step = 1; +if (!$start or !$end) { + print "start and end FPS values must be defined!\n" and exit; } if ($addr eq "" or $port eq 0) { @@ -92,10 +84,10 @@ if ($addr eq "" or $port eq 0) { if ($role eq "send") { system ("make $lib" . "_sender"); - send_benchmark($lib, $addr, $port, $iter, $threads, $start, $end, $step); + send_benchmark($lib, $addr, $port, $iter, $threads, $start, $end); } elsif ($role eq "recv" ){ system ("make $lib" . "_receiver"); - recv_benchmark($lib, $addr, $port, $iter, $threads, $start, $end, $step); + recv_benchmark($lib, $addr, $port, $iter, $threads, $start, $end); } else { print "invalid role: '$role'\n" and exit; } diff --git a/benchmarks/ffmpeg/sender.cc b/benchmarks/ffmpeg/sender.cc index 35c4792..c6c62dd 100644 --- a/benchmarks/ffmpeg/sender.cc +++ b/benchmarks/ffmpeg/sender.cc @@ -24,7 +24,7 @@ extern void *get_mem(int argc, char **argv, size_t& len); std::atomic nready(0); -void thread_func(void *mem, size_t len, int thread_num, int sleep) +void thread_func(void *mem, size_t len, int thread_num, double fps) { char addr[64] = { 0 }; enum AVCodecID codec_id = AV_CODEC_ID_H265; @@ -94,7 +94,7 @@ void thread_func(void *mem, size_t len, int thread_num, int sleep) av_interleaved_write_frame(avfctx, &pkt); av_packet_unref(&pkt); - std::this_thread::sleep_for(std::chrono::microseconds(sleep)); + std::this_thread::sleep_for(std::chrono::microseconds((int)((1000 / fps) * 1000))); i += chunk_size; frames++; @@ -120,7 +120,7 @@ void thread_func(void *mem, size_t len, int thread_num, int sleep) int main(int argc, char **argv) { if (argc != 3) { - fprintf(stderr, "usage: ./%s \n", __FILE__); + fprintf(stderr, "usage: ./%s \n", __FILE__); return -1; } @@ -134,7 +134,7 @@ int main(int argc, char **argv) std::thread **threads = (std::thread **)malloc(sizeof(std::thread *) * nthreads); for (int i = 0; i < nthreads; ++i) - threads[i] = new std::thread(thread_func, mem, len, i * 2, atoi(argv[2])); + threads[i] = new std::thread(thread_func, mem, len, i * 2, atof(argv[2])); while (nready.load() != nthreads) std::this_thread::sleep_for(std::chrono::milliseconds(20)); diff --git a/benchmarks/kvzrtp/sender.cc b/benchmarks/kvzrtp/sender.cc index e369ebb..80c1098 100644 --- a/benchmarks/kvzrtp/sender.cc +++ b/benchmarks/kvzrtp/sender.cc @@ -10,7 +10,7 @@ extern void *get_mem(int argc, char **argv, size_t& len); std::atomic nready(0); -void thread_func(void *mem, size_t len, int thread_num, int sleep) +void thread_func(void *mem, size_t len, int thread_num, double fps) { size_t bytes_sent = 0; uint64_t chunk_size = 0; @@ -44,8 +44,7 @@ void thread_func(void *mem, size_t len, int thread_num, int sleep) for (;;); } - if (sleep >= 100) - std::this_thread::sleep_for(std::chrono::microseconds(sleep)); + std::this_thread::sleep_for(std::chrono::microseconds((int)((1000 / fps) * 1000))); offset += chunk_size; bytes_sent += chunk_size; @@ -67,7 +66,7 @@ void thread_func(void *mem, size_t len, int thread_num, int sleep) int main(int argc, char **argv) { if (argc != 3) { - fprintf(stderr, "usage: ./%s \n", __FILE__); + fprintf(stderr, "usage: ./%s \n", __FILE__); return -1; } @@ -77,7 +76,7 @@ int main(int argc, char **argv) std::thread **threads = (std::thread **)malloc(sizeof(std::thread *) * nthreads); for (int i = 0; i < nthreads; ++i) - threads[i] = new std::thread(thread_func, mem, len, i * 2, atoi(argv[2])); + threads[i] = new std::thread(thread_func, mem, len, i * 2, atof(argv[2])); while (nready.load() != nthreads) std::this_thread::sleep_for(std::chrono::milliseconds(20));