2 * Copyright © 2016 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 #include "ao_scheme.h"
18 static char save_file[] = "scheme.image";
21 ao_scheme_os_save(void)
23 FILE *save = fopen(save_file, "w");
29 fwrite(ao_scheme_pool, 1, AO_SCHEME_POOL_TOTAL, save);
35 ao_scheme_os_restore_save(struct ao_scheme_os_save *save, int offset)
37 FILE *restore = fopen(save_file, "r");
44 fseek(restore, offset, SEEK_SET);
45 ret = fread(save, sizeof (struct ao_scheme_os_save), 1, restore);
53 ao_scheme_os_restore(void)
55 FILE *restore = fopen(save_file, "r");
62 ret = fread(ao_scheme_pool, 1, AO_SCHEME_POOL_TOTAL, restore);
64 if (ret != AO_SCHEME_POOL_TOTAL)
70 main (int argc, char **argv)
75 FILE *in = fopen(*argv, "r");
80 ao_scheme_read_eval_print(in, stdout, false);
83 ao_scheme_read_eval_print(stdin, stdout, true);
86 printf ("collects: full: %lu incremental %lu\n",
87 ao_scheme_collects[AO_SCHEME_COLLECT_FULL],
88 ao_scheme_collects[AO_SCHEME_COLLECT_INCREMENTAL]);
90 printf ("freed: full %lu incremental %lu\n",
91 ao_scheme_freed[AO_SCHEME_COLLECT_FULL],
92 ao_scheme_freed[AO_SCHEME_COLLECT_INCREMENTAL]);
94 printf("loops: full %lu incremental %lu\n",
95 ao_scheme_loops[AO_SCHEME_COLLECT_FULL],
96 ao_scheme_loops[AO_SCHEME_COLLECT_INCREMENTAL]);
98 printf("loops per collect: full %f incremental %f\n",
99 (double) ao_scheme_loops[AO_SCHEME_COLLECT_FULL] /
100 (double) ao_scheme_collects[AO_SCHEME_COLLECT_FULL],
101 (double) ao_scheme_loops[AO_SCHEME_COLLECT_INCREMENTAL] /
102 (double) ao_scheme_collects[AO_SCHEME_COLLECT_INCREMENTAL]);
104 printf("freed per collect: full %f incremental %f\n",
105 (double) ao_scheme_freed[AO_SCHEME_COLLECT_FULL] /
106 (double) ao_scheme_collects[AO_SCHEME_COLLECT_FULL],
107 (double) ao_scheme_freed[AO_SCHEME_COLLECT_INCREMENTAL] /
108 (double) ao_scheme_collects[AO_SCHEME_COLLECT_INCREMENTAL]);
110 printf("freed per loop: full %f incremental %f\n",
111 (double) ao_scheme_freed[AO_SCHEME_COLLECT_FULL] /
112 (double) ao_scheme_loops[AO_SCHEME_COLLECT_FULL],
113 (double) ao_scheme_freed[AO_SCHEME_COLLECT_INCREMENTAL] /
114 (double) ao_scheme_loops[AO_SCHEME_COLLECT_INCREMENTAL]);