add std::sort() to SortBench

Smaller is better, winner of each group marked with *:

   *  0.81  	sort_stdsort_repeated
      2.60  	sort_qsort_repeated
     11.06  	sort_skheap_repeated
     15.81  	sort_skqsort_repeated

   *  1.76  	sort_stdsort_backward
     23.17  	sort_qsort_backward
     14.32  	sort_skheap_backward
      7.06  	sort_skqsort_backward

   *  0.78  	sort_stdsort_forward
      4.00  	sort_qsort_forward
     15.19  	sort_skheap_forward
      2.76  	sort_skqsort_forward

     13.47  	sort_stdsort_rand10
     27.71  	sort_qsort_rand10
     15.80  	sort_skheap_rand10
   * 11.11  	sort_skqsort_rand10

     17.94  	sort_stdsort_rand
     48.69  	sort_qsort_rand
     16.52  	sort_skheap_rand
   * 11.98  	sort_skqsort_rand

libc++ must special case repeated, forward, and backward sorted data?

To reproduce, run this and ignore (unrelated) sort_topo_rand:

    $ ninja -C out nanobench; and out/nanobench -m sort_ -q

Change-Id: I3724188f2a6acac61d9e8c2bd43443792e0ae0ce
Reviewed-on: https://skia-review.googlesource.com/131156
Commit-Queue: Mike Klein <mtklein@chromium.org>
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Mike Klein <mtklein@chromium.org>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Mike Klein 2018-05-31 14:37:39 -04:00 committed by Skia Commit-Bot
parent d042071999
commit 2372a33523

View File

@ -9,7 +9,7 @@
#include "SkRandom.h"
#include "SkString.h"
#include "SkTSort.h"
#include <algorithm>
#include <stdlib.h>
static const int N = 1000;
@ -85,8 +85,12 @@ static void qsort_sort(int array[N]) {
qsort(array, N, sizeof(int), int_compare);
}
static void stdsort_sort(int array[N]) {
std::sort(array, array+N);
}
enum SortType {
kSKQSort, kSKHeap, kQSort
kSKQSort, kSKHeap, kQSort, kStdSort,
};
static const struct {
@ -94,8 +98,9 @@ static const struct {
SortProc fProc;
} gSorts[] = {
{ "skqsort", skqsort_sort },
{ "skheap", skheap_sort },
{ "qsort", qsort_sort },
{ "skheap", skheap_sort },
{ "qsort", qsort_sort },
{ "stdsort", stdsort_sort },
};
class SortBench : public Benchmark {
@ -152,23 +157,31 @@ static Benchmark* NewSkHeap(Type t) {
static Benchmark* NewQSort(Type t) {
return new SortBench(t, kQSort);
}
static Benchmark* NewStdSort(Type t) {
return new SortBench(t, kStdSort);
}
DEF_BENCH( return NewSkQSort(kRand); )
DEF_BENCH( return NewSkHeap(kRand); )
DEF_BENCH( return NewQSort(kRand); )
DEF_BENCH( return NewStdSort(kRand); )
DEF_BENCH( return NewSkQSort(kRandN); )
DEF_BENCH( return NewSkHeap(kRandN); )
DEF_BENCH( return NewQSort(kRandN); )
DEF_BENCH( return NewStdSort(kRandN); )
DEF_BENCH( return NewSkQSort(kFore); )
DEF_BENCH( return NewSkHeap(kFore); )
DEF_BENCH( return NewQSort(kFore); )
DEF_BENCH( return NewStdSort(kFore); )
DEF_BENCH( return NewSkQSort(kBack); )
DEF_BENCH( return NewSkHeap(kBack); )
DEF_BENCH( return NewQSort(kBack); )
DEF_BENCH( return NewStdSort(kBack); )
DEF_BENCH( return NewSkQSort(kSame); )
DEF_BENCH( return NewSkHeap(kSame); )
DEF_BENCH( return NewQSort(kSame); )
DEF_BENCH( return NewStdSort(kSame); )