/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ /* * GData Client * Copyright (C) Philip Withnall 2010, 2015 * * GData Client is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * GData Client is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with GData Client. If not, see . */ #include #include #include "gdata.h" #include "common.h" static void test_parse_feed (void) { GDataFeed *feed; GError *error = NULL; feed = GDATA_FEED (gdata_parsable_new_from_xml (GDATA_TYPE_FEED, "" "http://example.com/id" "2009-02-25T14:07:37.880860Z" "Test feed" "Test subtitle" "http://example.com/logo.png" "http://example.com/icon.png" "" "" "" "" "" "" "Joe Smith" "j.smith@example.com" "" "Example Generator" "2" "0" "50" "" "entry1" "Testing unhandled XML" "2009-01-25T14:07:37.880860Z" "2009-01-23T14:06:37.880860Z" "Here we test unhandled XML elements." "" "" "entry2" "Testing unhandled XML 2" "2009-02-25T14:07:37.880860Z" "2009-02-23T14:06:37.880860Z" "Here we test unhandled XML elements again." "" "", -1, &error)); g_assert_no_error (error); g_assert (GDATA_IS_FEED (feed)); g_clear_error (&error); g_object_unref (feed); } static void test_perf_parsing (void) { GTimeVal start_time, end_time; guint i; guint64 total_time; /* microseconds */ guint64 per_iteration_time; /* microseconds */ #define ITERATIONS 10000 /* Test feed parsing time */ g_get_current_time (&start_time); for (i = 0; i < ITERATIONS; i++) test_parse_feed (); g_get_current_time (&end_time); total_time = (end_time.tv_sec - start_time.tv_sec) * G_USEC_PER_SEC + (end_time.tv_usec - start_time.tv_usec); per_iteration_time = total_time / ITERATIONS; /* Prefix with hashes to avoid the output being misinterpreted as TAP * commands. */ printf ("# Parsing a feed %u times took:\n" "# • Total: %.4fs\n" "# • Per iteration: %.4fs\n", ITERATIONS, (gdouble) total_time / (gdouble) G_USEC_PER_SEC, (gdouble) per_iteration_time / (gdouble) G_USEC_PER_SEC); g_assert_cmpuint (per_iteration_time, <, 2000); /* 2ms */ } int main (int argc, char *argv[]) { gdata_test_init (argc, argv); g_test_add_func ("/perf/parsing", test_perf_parsing); return g_test_run (); }