Flutter Engine
The Flutter Engine
Classes | Typedefs | Enumerations | Functions | Variables
SortBench.cpp File Reference
#include "bench/Benchmark.h"
#include "include/core/SkString.h"
#include "include/private/base/SkTemplates.h"
#include "src/base/SkRandom.h"
#include "src/base/SkTSort.h"
#include <algorithm>
#include <stdlib.h>

Go to the source code of this file.

Classes

class  SortBench
 

Typedefs

typedef void(* SortProc) (int array[N])
 

Enumerations

enum  Type {
  kRand , kRandN , kFore , kBack ,
  kSame
}
 
enum  SortType { kSKQSort , kSKHeap , kQSort , kStdSort }
 

Functions

static void rand_proc (int array[N])
 
static void randN_proc (int array[N])
 
static void forward_proc (int array[N])
 
static void backward_proc (int array[N])
 
static void same_proc (int array[N])
 
static void skqsort_sort (int array[N])
 
static void skheap_sort (int array[N])
 
static int int_compare (const void *a, const void *b)
 
static void qsort_sort (int array[N])
 
static void stdsort_sort (int array[N])
 
static BenchmarkNewSkQSort (Type t)
 
static BenchmarkNewSkHeap (Type t)
 
static BenchmarkNewQSort (Type t)
 
static BenchmarkNewStdSort (Type t)
 

Variables

static const int N = 1000
 
struct {
   const char *   fName
 
   SortProc   fProc
 
gRec []
 
struct {
   const char *   fName
 
   SortProc   fProc
 
gSorts []
 

Typedef Documentation

◆ SortProc

typedef void(* SortProc) (int array[N])

Definition at line 54 of file SortBench.cpp.

Enumeration Type Documentation

◆ SortType

enum SortType
Enumerator
kSKQSort 
kSKHeap 
kQSort 
kStdSort 

Definition at line 95 of file SortBench.cpp.

95 {
97};
@ kSKQSort
Definition: SortBench.cpp:96
@ kQSort
Definition: SortBench.cpp:96
@ kStdSort
Definition: SortBench.cpp:96
@ kSKHeap
Definition: SortBench.cpp:96

◆ Type

enum Type
Enumerator
kRand 
kRandN 
kFore 
kBack 
kSame 

Definition at line 56 of file SortBench.cpp.

56 {
58};
@ kFore
Definition: SortBench.cpp:57
@ kSame
Definition: SortBench.cpp:57
@ kRand
Definition: SortBench.cpp:57
@ kRandN
Definition: SortBench.cpp:57
@ kBack
Definition: SortBench.cpp:57

Function Documentation

◆ backward_proc()

static void backward_proc ( int  array[N])
static

Definition at line 42 of file SortBench.cpp.

42 {
43 for (int i = 0; i < N; ++i) {
44 array[i] = -i;
45 }
46}
static const int N
Definition: SortBench.cpp:19

◆ forward_proc()

static void forward_proc ( int  array[N])
static

Definition at line 36 of file SortBench.cpp.

36 {
37 for (int i = 0; i < N; ++i) {
38 array[i] = i;
39 }
40}

◆ int_compare()

static int int_compare ( const void *  a,
const void *  b 
)
static

Definition at line 80 of file SortBench.cpp.

80 {
81 const int ai = *(const int*)a;
82 const int bi = *(const int*)b;
83 return ai < bi ? -1 : (ai > bi);
84 }
static bool b
struct MyStruct a[10]

◆ NewQSort()

static Benchmark * NewQSort ( Type  t)
static

Definition at line 160 of file SortBench.cpp.

160 {
161 return new SortBench(t, kQSort);
162}

◆ NewSkHeap()

static Benchmark * NewSkHeap ( Type  t)
static

Definition at line 157 of file SortBench.cpp.

157 {
158 return new SortBench(t, kSKHeap);
159}

◆ NewSkQSort()

static Benchmark * NewSkQSort ( Type  t)
static

Definition at line 154 of file SortBench.cpp.

154 {
155 return new SortBench(t, kSKQSort);
156}

◆ NewStdSort()

static Benchmark * NewStdSort ( Type  t)
static

Definition at line 163 of file SortBench.cpp.

163 {
164 return new SortBench(t, kStdSort);
165}

◆ qsort_sort()

static void qsort_sort ( int  array[N])
static

Definition at line 87 of file SortBench.cpp.

87 {
88 qsort(array, N, sizeof(int), int_compare);
89}
static int int_compare(const void *a, const void *b)
Definition: SortBench.cpp:80

◆ rand_proc()

static void rand_proc ( int  array[N])
static

Definition at line 21 of file SortBench.cpp.

21 {
22 SkRandom rand;
23 for (int i = 0; i < N; ++i) {
24 array[i] = rand.nextS();
25 }
26}
int32_t nextS()
Definition: SkRandom.h:50

◆ randN_proc()

static void randN_proc ( int  array[N])
static

Definition at line 28 of file SortBench.cpp.

28 {
29 SkRandom rand;
30 int mod = N / 10;
31 for (int i = 0; i < N; ++i) {
32 array[i] = rand.nextU() % mod;
33 }
34}
uint32_t nextU()
Definition: SkRandom.h:42

◆ same_proc()

static void same_proc ( int  array[N])
static

Definition at line 48 of file SortBench.cpp.

48 {
49 for (int i = 0; i < N; ++i) {
50 array[i] = N;
51 }
52}

◆ skheap_sort()

static void skheap_sort ( int  array[N])
static

Definition at line 75 of file SortBench.cpp.

75 {
76 SkTHeapSort<int>(array, N);
77}

◆ skqsort_sort()

static void skqsort_sort ( int  array[N])
static

Definition at line 71 of file SortBench.cpp.

71 {
72 SkTQSort<int>(array, array + N);
73}

◆ stdsort_sort()

static void stdsort_sort ( int  array[N])
static

Definition at line 91 of file SortBench.cpp.

91 {
92 std::sort(array, array+N);
93}
static std::vector< SkPDFIndirectReference > sort(const THashSet< SkPDFIndirectReference > &src)

Variable Documentation

◆ fName

const char* fName

Definition at line 61 of file SortBench.cpp.

◆ fProc

SortProc fProc

Definition at line 62 of file SortBench.cpp.

◆ 

const struct { ... } gRec[]
Initial value:
= {
{ "rand", rand_proc },
{ "rand10", randN_proc },
{ "forward", forward_proc },
{ "backward", backward_proc },
{ "repeated", same_proc },
}
static void randN_proc(int array[N])
Definition: SortBench.cpp:28
static void backward_proc(int array[N])
Definition: SortBench.cpp:42
static void rand_proc(int array[N])
Definition: SortBench.cpp:21
static void same_proc(int array[N])
Definition: SortBench.cpp:48
static void forward_proc(int array[N])
Definition: SortBench.cpp:36

◆ 

const struct { ... } gSorts[]
Initial value:
= {
{ "skqsort", skqsort_sort },
{ "skheap", skheap_sort },
{ "qsort", qsort_sort },
{ "stdsort", stdsort_sort },
}
static void qsort_sort(int array[N])
Definition: SortBench.cpp:87
static void skheap_sort(int array[N])
Definition: SortBench.cpp:75
static void stdsort_sort(int array[N])
Definition: SortBench.cpp:91
static void skqsort_sort(int array[N])
Definition: SortBench.cpp:71

◆ N

const int N = 1000
static

Definition at line 19 of file SortBench.cpp.