| 2227 | } |
| 2228 | |
| 2229 | static double histogramRectMicroBench( GPUEnv *env, TessScoreEvaluationInputData input, ds_device_type type ) { |
| 2230 | double time; |
| 2231 | #if ON_WINDOWS |
| 2232 | LARGE_INTEGER freq, time_funct_start, time_funct_end; |
| 2233 | QueryPerformanceFrequency(&freq); |
| 2234 | #elif ON_APPLE |
| 2235 | mach_timebase_info_data_t info = {0, 0}; |
| 2236 | mach_timebase_info(&info); |
| 2237 | long long start, stop; |
| 2238 | #else |
| 2239 | timespec time_funct_start, time_funct_end; |
| 2240 | #endif |
| 2241 | |
| 2242 | int left = 0; |
| 2243 | int top = 0; |
| 2244 | int kHistogramSize = 256; |
| 2245 | int bytes_per_line = input.width*input.numChannels; |
| 2246 | int *histogramAllChannels = new int[kHistogramSize*input.numChannels]; |
| 2247 | // function call |
| 2248 | if (type == DS_DEVICE_OPENCL_DEVICE) { |
| 2249 | #if ON_WINDOWS |
| 2250 | QueryPerformanceCounter(&time_funct_start); |
| 2251 | #elif ON_APPLE |
| 2252 | start = mach_absolute_time(); |
| 2253 | #else |
| 2254 | clock_gettime( CLOCK_MONOTONIC, &time_funct_start ); |
| 2255 | #endif |
| 2256 | |
| 2257 | OpenclDevice::gpuEnv = *env; |
| 2258 | int retVal = OpenclDevice::HistogramRectOCL( |
| 2259 | input.imageData, input.numChannels, bytes_per_line, top, left, |
| 2260 | input.width, input.height, kHistogramSize, histogramAllChannels); |
| 2261 | |
| 2262 | #if ON_WINDOWS |
| 2263 | QueryPerformanceCounter(&time_funct_end); |
| 2264 | time = (time_funct_end.QuadPart-time_funct_start.QuadPart)/(double)(freq.QuadPart); |
| 2265 | #elif ON_APPLE |
| 2266 | stop = mach_absolute_time(); |
| 2267 | if (retVal == 0) { |
| 2268 | time = ((stop - start) * (double)info.numer / info.denom) / 1.0E9; |
| 2269 | } else { |
| 2270 | time = FLT_MAX; |
| 2271 | } |
| 2272 | #else |
| 2273 | clock_gettime( CLOCK_MONOTONIC, &time_funct_end ); |
| 2274 | time = (time_funct_end.tv_sec - time_funct_start.tv_sec)*1.0 + (time_funct_end.tv_nsec - time_funct_start.tv_nsec)/1000000000.0; |
| 2275 | #endif |
| 2276 | } else { |
| 2277 | int *histogram = new int[kHistogramSize]; |
| 2278 | #if ON_WINDOWS |
| 2279 | QueryPerformanceCounter(&time_funct_start); |
| 2280 | #elif ON_APPLE |
| 2281 | start = mach_absolute_time(); |
| 2282 | #else |
| 2283 | clock_gettime( CLOCK_MONOTONIC, &time_funct_start ); |
| 2284 | #endif |
| 2285 | for (int ch = 0; ch < input.numChannels; ++ch) { |
| 2286 | tesseract::HistogramRect(input.pix, input.numChannels, left, top, |
no test coverage detected