1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

avfilter/vf_removegrain: replace qsort with AV_QSORT

filter_slice calls qsort, so qsort is in a performance critical
position. AV_QSORT is substantially faster due to the inlining of the
comparison callback. Thus, the increase in performance is worth the
increase in binary size.

Sample benchmark (x86-64, Haswell, GNU/Linux),
filter-removegrain-mode-02 (from FATE)
new:
  24060 decicycles in qsort,       1 runs,      0 skips
  15690 decicycles in qsort,       2 runs,      0 skips
   9307 decicycles in qsort,       4 runs,      0 skips
   5572 decicycles in qsort,       8 runs,      0 skips
   3485 decicycles in qsort,      16 runs,      0 skips
   2517 decicycles in qsort,      32 runs,      0 skips
   1979 decicycles in qsort,      64 runs,      0 skips
   1911 decicycles in qsort,     128 runs,      0 skips
   1568 decicycles in qsort,     256 runs,      0 skips
   1596 decicycles in qsort,     512 runs,      0 skips
   1614 decicycles in qsort,    1024 runs,      0 skips
   1874 decicycles in qsort,    2046 runs,      2 skips
   2186 decicycles in qsort,    4094 runs,      2 skips

old:
 246960 decicycles in qsort,       1 runs,      0 skips
 135765 decicycles in qsort,       2 runs,      0 skips
  70920 decicycles in qsort,       4 runs,      0 skips
  37710 decicycles in qsort,       8 runs,      0 skips
  20831 decicycles in qsort,      16 runs,      0 skips
  12225 decicycles in qsort,      32 runs,      0 skips
   8083 decicycles in qsort,      64 runs,      0 skips
   6270 decicycles in qsort,     128 runs,      0 skips
   5321 decicycles in qsort,     256 runs,      0 skips
   4860 decicycles in qsort,     512 runs,      0 skips
   4424 decicycles in qsort,    1024 runs,      0 skips
   4191 decicycles in qsort,    2046 runs,      2 skips
   4934 decicycles in qsort,    4094 runs,      2 skips

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
This commit is contained in:
Ganesh Ajjanagadde 2015-10-25 15:06:01 -04:00
parent ff1e44b01e
commit 68a0a164d1

View File

@ -24,6 +24,7 @@
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/qsort.h"
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
@ -92,7 +93,7 @@ static int mode02(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7,
{
int a[8] = { a1, a2, a3, a4, a5, a6, a7, a8 };
qsort(&a, 8, sizeof(a[0]), cmp_int);
AV_QSORT(a, 8, int, cmp_int);
return av_clip(c, a[2 - 1 ], a[7 - 1]);
}
@ -101,7 +102,7 @@ static int mode03(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7,
{
int a[8] = { a1, a2, a3, a4, a5, a6, a7, a8 };
qsort(&a, 8, sizeof(a[0]), cmp_int);
AV_QSORT(a, 8, int, cmp_int);
return av_clip(c, a[3 - 1 ], a[6 - 1]);
}
@ -110,7 +111,7 @@ static int mode04(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7,
{
int a[8] = { a1, a2, a3, a4, a5, a6, a7, a8 };
qsort(&a, 8, sizeof(a[0]), cmp_int);
AV_QSORT(a, 8, int, cmp_int);
return av_clip(c, a[4 - 1 ], a[5 - 1]);
}