From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <ffmpeg-devel-bounces@ffmpeg.org> Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 0884E4E81A for <ffmpegdev@gitmailbox.com>; Mon, 17 Mar 2025 10:45:16 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EBB9668B9D3; Mon, 17 Mar 2025 12:44:14 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 39F2868B0ED for <ffmpeg-devel@ffmpeg.org>; Mon, 17 Mar 2025 12:44:06 +0200 (EET) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with UTF8SMTP id A6625434F2; Mon, 17 Mar 2025 11:44:02 +0100 (CET) From: Niklas Haas <ffmpeg@haasn.xyz> To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Mar 2025 11:43:52 +0100 Message-ID: <20250317104357.307832-6-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250317104357.307832-1-ffmpeg@haasn.xyz> References: <20250317104357.307832-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/11] tests/swscale: print performance stats on exit X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org> List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe> List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel> List-Post: <mailto:ffmpeg-devel@ffmpeg.org> List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help> List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe> Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: Niklas Haas <git@haasn.dev> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250317104357.307832-6-ffmpeg@haasn.xyz/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> From: Niklas Haas <git@haasn.dev> --- libswscale/tests/swscale.c | 47 ++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c index ea6c57ff2a..a2b960faa3 100644 --- a/libswscale/tests/swscale.c +++ b/libswscale/tests/swscale.c @@ -24,6 +24,7 @@ #include <string.h> #include <inttypes.h> #include <stdarg.h> +#include <signal.h> #undef HAVE_AV_CONFIG_H #include "libavutil/cpu.h" @@ -71,6 +72,33 @@ const SwsFlags flags[] = { static FFSFC64 prng_state; static SwsContext *sws[3]; /* reused between tests for efficiency */ +static double speedup_logavg; +static double speedup_min = 1e10; +static double speedup_max = 0; +static int speedup_count; + +static const char *speedup_color(double ratio) +{ + return ratio > 1.10 ? "\033[1;32m" : /* bold green */ + ratio > 1.02 ? "\033[32m" : /* green */ + ratio > 0.98 ? "" : /* default */ + ratio > 0.95 ? "\033[33m" : /* yellow */ + ratio > 0.90 ? "\033[31m" : /* red */ + "\033[1;31m"; /* bold red */ +} + +static void exit_handler(int sig) +{ + if (speedup_count) { + double ratio = exp(speedup_logavg / speedup_count); + printf("Overall speedup=%.3fx %s%s\033[0m, min=%.3fx max=%.3fx\n", ratio, + speedup_color(ratio), ratio >= 1.0 ? "faster" : "slower", + speedup_min, speedup_max); + } + + exit(sig); +} + static int fmt_comps(enum AVPixelFormat fmt) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); @@ -261,16 +289,16 @@ static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, if (opts.bench && time_ref) { double ratio = (double) time_ref / time; - const char *color = ratio > 1.10 ? "\033[1;32m" : /* bold green */ - ratio > 1.02 ? "\033[32m" : /* green */ - ratio > 0.98 ? "" : /* default */ - ratio > 0.95 ? "\033[33m" : /* yellow */ - ratio > 0.90 ? "\033[31m" : /* red */ - "\033[1;31m"; /* bold red */ + if (FFMIN(time, time_ref) > 100 /* don't pollute stats with low precision */) { + speedup_min = FFMIN(speedup_min, ratio); + speedup_max = FFMAX(speedup_max, ratio); + speedup_logavg += log(ratio); + speedup_count++; + } printf(" time=%"PRId64" us, ref=%"PRId64" us, speedup=%.3fx %s%s\033[0m\n", - time / opts.iters, time_ref / opts.iters, ratio, color, - ratio >= 1.0 ? "faster" : "slower"); + time / opts.iters, time_ref / opts.iters, ratio, + speedup_color(ratio), ratio >= 1.0 ? "faster" : "slower"); } else if (opts.bench) { printf(" time=%"PRId64" us\n", time / opts.iters); } @@ -492,6 +520,7 @@ bad_option: ff_sfc64_init(&prng_state, 0, 0, 0, 12); av_lfg_init(&rand, 1); + signal(SIGINT, exit_handler); for (int i = 0; i < 3; i++) { sws[i] = sws_alloc_context(); @@ -537,5 +566,5 @@ error: av_frame_free(&ref); if (fp) fclose(fp); - return ret; + exit_handler(ret); } -- 2.48.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".