1 | /* lognestmonster Copyright (c) 2020 Joshua 'joshuas3' Stockin |
2 | * <https://joshstock.in> |
3 | * <https://github.com/JoshuaS3/lognestmonster> |
4 | * |
5 | * This software is licensed and distributed under the terms of the MIT License. |
6 | * See the MIT License in the LICENSE file of this project's root folder. |
7 | * |
8 | * This comment block and its contents, including this disclaimer, MUST be |
9 | * preserved in all copies or distributions of this software's source. |
10 | */ |
11 |
|
12 | // header_memory.c |
13 | // Test memory usage on lognestmonster library to prevent leaks |
14 |
|
15 | #include <stdio.h> |
16 |
|
17 | #define LNM_INIT |
18 | #define LNM_ALL |
19 | #define LNM_DEBUG |
20 | #include "lognestmonster.h" |
21 |
|
22 | int main() { |
23 | long t1 = lnm_getus(); |
24 |
|
25 | lnmItem lastEvent = NULL; |
26 | for (int iter = 0; iter < 25000; iter++) { |
27 | uint64_t time = lnm_getus(); |
28 | int type = time % 5 == 0 ? LNM_EVENT : LNM_STATEMENT; |
29 | if (type == LNM_STATEMENT) { |
30 | char message[25]; |
31 | snprintf(message, 25, "New statement #%i", iter); |
32 | if (lastEvent == NULL) { |
33 | lnmStatement(lnmInfo, message); |
34 | } else { |
35 | lnmEventPushS(lastEvent, lnmInfo, message); |
36 | } |
37 | } else if (type == LNM_EVENT) { |
38 | char tag[20]; |
39 | snprintf(tag, 20, "New event #%i", iter); |
40 | if (lastEvent == NULL || time % 7 == 0) { |
41 | lastEvent = lnmEvent(tag); |
42 | } else { |
43 | lnmItem new_event = lnmEvent(tag); |
44 | lnmEventPush(lastEvent, new_event); |
45 | lastEvent = new_event; |
46 | } |
47 | } |
48 | } |
49 | lnm_registry_free(); |
50 | printf("time elapsed (us): %lu\n", lnm_getus() - t1); |
51 | return 0; |
52 | } |
53 |
|