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 #ifdef HAVE_MACH_MACH_TIME_H
36 #include <mach/mach_time.h>
48 res = mach_absolute_time () / 1000000000.;
51 clock_gettime (CLOCK_MONOTONIC, &ts);
53 res = (double)ts.tv_sec + ts.tv_nsec / 1000000000.;
60 main (int argc, char **argv)
63 struct ucl_parser *parser;
66 unsigned char *emitted;
68 const char *fname_in = NULL;
70 double start, end, seconds;
78 fin = open (fname_in, O_RDONLY);
80 perror ("open failed");
83 parser = ucl_parser_new (UCL_PARSER_ZEROCOPY);
85 (void)fstat (fin, &st);
86 map = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fin, 0);
87 if (map == MAP_FAILED) {
88 perror ("mmap failed");
95 ucl_parser_add_chunk (parser, map, st.st_size);
97 obj = ucl_parser_get_object (parser);
100 seconds = end - start;
101 printf ("ucl: parsed input in %.4f seconds\n", seconds);
102 if (ucl_parser_get_error(parser)) {
103 printf ("Error occurred: %s\n", ucl_parser_get_error(parser));
108 start = get_ticks ();
109 emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
112 seconds = end - start;
113 printf ("ucl: emitted config in %.4f seconds\n", seconds);
117 start = get_ticks ();
118 emitted = ucl_object_emit (obj, UCL_EMIT_JSON);
121 seconds = end - start;
122 printf ("ucl: emitted json in %.4f seconds\n", seconds);
126 start = get_ticks ();
127 emitted = ucl_object_emit (obj, UCL_EMIT_JSON_COMPACT);
130 seconds = end - start;
131 printf ("ucl: emitted compact json in %.4f seconds\n", seconds);
135 start = get_ticks ();
136 emitted = ucl_object_emit (obj, UCL_EMIT_YAML);
139 seconds = end - start;
140 printf ("ucl: emitted yaml in %.4f seconds\n", seconds);
144 ucl_parser_free (parser);
145 ucl_object_unref (obj);
148 munmap (map, st.st_size);