• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  **
3  ** Copyright 2009, The Android Open Source Project
4  **
5  ** Licensed under the Apache License, Version 2.0 (the "License");
6  ** you may not use this file except in compliance with the License.
7  ** You may obtain a copy of the License at
8  **
9  **     http://www.apache.org/licenses/LICENSE-2.0
10  **
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  */
17 
18 #define LOG_TAG "StopWatch"
19 
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <utils/StopWatch.h>
23 #include <utils/Log.h>
24 
25 #include <ui/GraphicBuffer.h>
26 #include <ui/GraphicBufferMapper.h>
27 
28 using namespace android;
29 
lamecpy(void * d,void const * s,size_t size)30 void* lamecpy(void* d, void const* s, size_t size) {
31     char* dst = (char*)d;
32     char const* src = (char const*)s;
33     while (size) {
34         *dst++ = *src++;
35         size--;
36     }
37     return d;
38 }
39 
main(int,char **)40 int main(int /*argc*/, char** /*argv*/)
41 {
42     size_t size = 128*256*4;
43     void* temp = malloc(size);
44     void* temp2 = malloc(size);
45     memset(temp, 0, size);
46     memset(temp2, 0, size);
47 
48 
49     sp<GraphicBuffer> buffer = new GraphicBuffer(128, 256, HAL_PIXEL_FORMAT_RGBA_8888,
50             GRALLOC_USAGE_SW_READ_OFTEN |
51             GRALLOC_USAGE_SW_WRITE_OFTEN);
52 
53     status_t err = buffer->initCheck();
54     if (err != NO_ERROR) {
55         printf("%s\n", strerror(-err));
56         return 0;
57     }
58 
59     void* vaddr;
60     buffer->lock(
61             GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
62             &vaddr);
63 
64     {
65         StopWatch watch("memset");
66         for (int i=0 ; i<10 ; i++)
67             memset(vaddr, 0, size);
68     }
69 
70     {
71         StopWatch watch("memcpy baseline");
72         for (int i=0 ; i<10 ; i++)
73             memcpy(temp, temp2, size);
74     }
75 
76     {
77         StopWatch watch("memcpy from gralloc");
78         for (int i=0 ; i<10 ; i++)
79             memcpy(temp, vaddr, size);
80     }
81 
82     {
83         StopWatch watch("memcpy into gralloc");
84         for (int i=0 ; i<10 ; i++)
85             memcpy(vaddr, temp, size);
86     }
87 
88 
89     {
90         StopWatch watch("lamecpy baseline");
91         for (int i=0 ; i<10 ; i++)
92             lamecpy(temp, temp2, size);
93     }
94 
95     {
96         StopWatch watch("lamecpy from gralloc");
97         for (int i=0 ; i<10 ; i++)
98             lamecpy(temp, vaddr, size);
99     }
100 
101     {
102         StopWatch watch("lamecpy into gralloc");
103         for (int i=0 ; i<10 ; i++)
104             lamecpy(vaddr, temp, size);
105     }
106 
107     buffer->unlock();
108 
109     return 0;
110 }
111