1 /* Copyright (c) 2013, Vsevolod Stakhov
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
12 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
13 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
16 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 #include <sys/types.h>
35 #include <mach/mach_time.h>
46 res = mach_absolute_time () / 1000000000.;
49 clock_gettime (CLOCK_MONOTONIC, &ts);
51 res = (double)ts.tv_sec + ts.tv_nsec / 1000000000.;
58 main (int argc, char **argv)
61 struct ucl_parser *parser;
64 unsigned char *emitted;
66 const char *fname_in = NULL;
68 double start, end, seconds;
76 fin = open (fname_in, O_RDONLY);
78 perror ("open failed");
81 parser = ucl_parser_new (UCL_PARSER_ZEROCOPY);
83 (void)fstat (fin, &st);
84 map = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fin, 0);
85 if (map == MAP_FAILED) {
86 perror ("mmap failed");
93 ucl_parser_add_chunk (parser, map, st.st_size);
95 obj = ucl_parser_get_object (parser);
98 seconds = end - start;
99 printf ("ucl: parsed input in %.4f seconds\n", seconds);
100 if (ucl_parser_get_error(parser)) {
101 printf ("Error occurred: %s\n", ucl_parser_get_error(parser));
106 start = get_ticks ();
107 emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
110 seconds = end - start;
111 printf ("ucl: emitted config in %.4f seconds\n", seconds);
115 start = get_ticks ();
116 emitted = ucl_object_emit (obj, UCL_EMIT_JSON);
119 seconds = end - start;
120 printf ("ucl: emitted json in %.4f seconds\n", seconds);
124 start = get_ticks ();
125 emitted = ucl_object_emit (obj, UCL_EMIT_JSON_COMPACT);
128 seconds = end - start;
129 printf ("ucl: emitted compact json in %.4f seconds\n", seconds);
133 start = get_ticks ();
134 emitted = ucl_object_emit (obj, UCL_EMIT_YAML);
137 seconds = end - start;
138 printf ("ucl: emitted yaml in %.4f seconds\n", seconds);
142 ucl_parser_free (parser);
143 ucl_object_unref (obj);
146 munmap (map, st.st_size);