FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
prim_test.c
1/* prim_test.c
2 * vi:ts=4 sw=4
3 *
4 * (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15#include <freerdp/config.h>
16
17#include "prim_test.h"
18
19#ifndef _WIN32
20#include <fcntl.h>
21#include <math.h>
22#include <sys/types.h>
23#include <sys/stat.h>
24#endif
25
26#include <winpr/sysinfo.h>
27#include <winpr/platform.h>
28#include <winpr/crypto.h>
29
30primitives_t* generic = NULL;
31primitives_t* optimized = NULL;
32BOOL g_TestPrimitivesPerformance = FALSE;
33UINT32 g_Iterations = 1000;
34
35int test_sizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };
36
37/* ------------------------------------------------------------------------- */
38
39float measure_delta_time(UINT64 t0, UINT64 t1)
40{
41 INT64 diff = (INT64)(t1 - t0);
42 double retval = ((double)diff / 1000000000.0);
43 return (retval < 0.0) ? 0.0f : (float)retval;
44}
45
46/* ------------------------------------------------------------------------- */
47void measure_floatprint(float t, char* output, size_t len)
48{
49 /* I don't want to link against -lm, so avoid log,exp,... */
50 float f = 10.0f;
51 int i = 0;
52
53 while (t > f)
54 f *= 10.0f;
55
56 f /= 1000.0f;
57 i = ((int)(t / f + 0.5f)) * (int)f;
58
59 if (t < 0.0f)
60 (void)_snprintf(output, len, "%f", t);
61 else if (i == 0)
62 (void)_snprintf(output, len, "%d", (int)(t + 0.5f));
63 else if (t < 1e+3f)
64 (void)_snprintf(output, len, "%3d", i);
65 else if (t < 1e+6f)
66 (void)_snprintf(output, len, "%3d,%03d", i / 1000, i % 1000);
67 else if (t < 1e+9f)
68 (void)_snprintf(output, len, "%3d,%03d,000", i / 1000000, (i % 1000000) / 1000);
69 else if (t < 1e+12f)
70 (void)_snprintf(output, len, "%3d,%03d,000,000", i / 1000000000,
71 (i % 1000000000) / 1000000);
72 else
73 (void)_snprintf(output, len, "%f", t);
74}
75
76void prim_test_setup(BOOL performance)
77{
78 generic = primitives_get_generic();
79 optimized = primitives_get();
80 g_TestPrimitivesPerformance = performance;
81}
82
83BOOL speed_test(const char* name, const char* dsc, UINT32 iterations, speed_test_fkt generic,
84 speed_test_fkt optimized, ...)
85{
86 if (!name || !generic || !optimized || (iterations == 0))
87 return FALSE;
88
89 for (UINT32 i = 0; i < iterations; i++)
90 {
91 }
92
93 return TRUE;
94}