aboutsummaryrefslogtreecommitdiff
path: root/jerry-main/benchmarking.c
blob: 0040d86a57ee2c03f61aaad7d19f45498eb54bc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Copyright JS Foundation and other contributors, http://js.foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * This source contains libc overrides for the sake of stable benchmarking. If
 * building a binary for the purpose of benchmarking, the object compiled from
 * this source is to be injected into the list of objects-to-be-linked before
 * the list of libraries-to-be-linked to ensure that the linker picks up these
 * implementations.
 */

#ifdef __GNUC__
/*
 * Note:
 *      This is nasty and dangerous. However, we only need the timeval structure
 *      from sys/time.h. Unfortunately, the same header also declares
 *      gettimeofday, which has different declarations on different platforms
 *      (e.g., macOS, Linux). So, instead of #ifdef'ing for platforms, we simply
 *      tweak the header to declare another function. Don't try this at home.
 */
#define gettimeofday __prevent_conflicting_gettimeofday_declarations__
#include <sys/time.h>
#undef gettimeofday

int gettimeofday (struct timeval *, void *);

/**
 * Useless but stable gettimeofday implementation. Returns Epoch. Ensures that
 * test cases relying on "now" yield stable results.
 */
int
gettimeofday (struct timeval *tv, void *tz)
{
  (void) tz;
  tv->tv_sec = 0;
  tv->tv_usec = 0;
  return 0;
} /* gettimeofday */
#endif /* __GNUC__ */

int rand (void);

/**
 * Useless but stable rand implementation. Returns 4. Ensures that test cases
 * relying on randomness yield stable results.
 */
int
rand (void)
{
  return 4; /* Chosen by fair dice roll. Guaranteed to be random. */
} /* rand */