| 2 | #include "dsl.h" |
| 3 | |
| 4 | void dsl_benchmarks() { |
| 5 | hc_time_t t; |
| 6 | const int n = 100000; |
| 7 | |
| 8 | char buf[32]; |
| 9 | t = hc_now(); |
| 10 | |
| 11 | for (int i = 0; i < n; i++) { |
| 12 | sprintf(buf, "abc %s def", "ghi"); |
| 13 | } |
| 14 | |
| 15 | hc_time_print(&t, "sprintf: "); |
| 16 | |
| 17 | struct hc_dsl dsl; |
| 18 | hc_dsl_init(&dsl, &hc_malloc_default); |
| 19 | hc_defer(hc_dsl_deinit(&dsl)); |
| 20 | struct hc_memory_stream out; |
| 21 | hc_memory_stream_init(&out, &hc_malloc_default); |
| 22 | hc_defer(hc_stream_deinit(&out.stream)); |
| 23 | dsl.out = &out.stream; |
| 24 | hc_dsl_set_string(&dsl, "foo", "ghi"); |
| 25 | hc_dsl_eval(&dsl, "abc $(print foo) def"); |
| 26 | |
| 27 | t = hc_now(); |
| 28 | |
| 29 | for (int i = 0; i < n; i++) { |
| 30 | hc_vector_clear(&out.data); |
| 31 | hc_vm_eval(&dsl.vm, 0, -1); |
| 32 | } |
| 33 | |
| 34 | hc_time_print(&t, "dsl: "); |
| 35 | } |
no test coverage detected