mirror of
https://github.com/flatpak/flatpak.git
synced 2026-04-07 08:34:25 -04:00
Add performance test
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,3 +2,5 @@ ostree_test
|
||||
ostree_test.h
|
||||
sample
|
||||
sample.h
|
||||
performance
|
||||
performance.h
|
||||
|
||||
10
Makefile
10
Makefile
@@ -1,4 +1,4 @@
|
||||
all: sample ostree_test
|
||||
all: sample ostree_test performance
|
||||
|
||||
sample.h: variant-schema-compiler sample.gv
|
||||
./variant-schema-compiler --outfile sample.h --prefix=sample sample.gv
|
||||
@@ -6,6 +6,12 @@ sample.h: variant-schema-compiler sample.gv
|
||||
sample: sample.c sample.h
|
||||
gcc `pkg-config --cflags --libs glib-2.0` -g -Wall -o sample sample.c
|
||||
|
||||
performance.h: variant-schema-compiler performance.gv
|
||||
./variant-schema-compiler --outfile performance.h --prefix=performance performance.gv
|
||||
|
||||
performance: performance.c performance.h
|
||||
gcc `pkg-config --cflags --libs glib-2.0` -O2 -o performance performance.c
|
||||
|
||||
ostree_test.h: variant-schema-compiler ostree.gv
|
||||
./variant-schema-compiler --outfile ostree_test.h --prefix=ot ostree.gv
|
||||
|
||||
@@ -13,4 +19,4 @@ ostree_test: ostree_test.c ostree_test.h
|
||||
gcc `pkg-config --cflags --libs glib-2.0` -g -Wall -o ostree_test ostree_test.c
|
||||
|
||||
clean:
|
||||
rm -f sample.h sample ostree_test.h ostree_test
|
||||
rm -f sample.h sample performance.h performance ostree_test.h ostree_test
|
||||
|
||||
127
performance.c
Normal file
127
performance.c
Normal file
@@ -0,0 +1,127 @@
|
||||
#include "performance.h"
|
||||
|
||||
gint32
|
||||
sum_gvariant (GVariant *v)
|
||||
{
|
||||
guint32 sum;
|
||||
gint16 a;
|
||||
gint32 b;
|
||||
const char *c;
|
||||
GVariant *list;
|
||||
guchar d;
|
||||
guint16 tuple_a;
|
||||
guchar tuple_b;
|
||||
gsize len, i;
|
||||
gint32 list_a;
|
||||
guint16 list_b;
|
||||
|
||||
g_variant_get (v, "(ni&s@a(iq)y(qy))",
|
||||
&a, &b, &c, &list, &d, &tuple_a, &tuple_b);
|
||||
sum = a + b + strlen(c) + d + tuple_a + tuple_b;
|
||||
|
||||
len = g_variant_n_children (list);
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
g_variant_get_child (list, i, "(iq)", &list_a, &list_b);
|
||||
sum += list_a + list_b;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
gint32
|
||||
sum_generated (PerformanceContainerRef v)
|
||||
{
|
||||
guint32 sum;
|
||||
PerformanceTupleRef tuple;
|
||||
PerformanceListRef list;
|
||||
PerformanceItemRef item;
|
||||
gsize len, i;
|
||||
|
||||
tuple = performance_container_ref_get_tuple (v);
|
||||
sum = performance_container_ref_get_a(v) +
|
||||
performance_container_ref_get_b(v) +
|
||||
strlen(performance_container_ref_get_c(v)) +
|
||||
performance_container_ref_get_d(v) +
|
||||
performance_tuple_ref_get_a (tuple) +
|
||||
performance_tuple_ref_get_b (tuple);
|
||||
|
||||
list = performance_container_ref_get_list (v);
|
||||
len = performance_list_ref_get_length (list);
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
item = performance_list_ref_get_at (list, i);
|
||||
sum += performance_item_ref_get_a (item) + performance_item_ref_get_b (item);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
GVariant *v;
|
||||
gconstpointer serialized_data;
|
||||
int i, count = 100000;
|
||||
guint64 total;
|
||||
GTimer *timer = g_timer_new ();
|
||||
PerformanceContainerRef c;
|
||||
|
||||
#define DATA "(int16 17, 32, 'foobar', [(44, uint16 12), (48, uint16 14), (99, uint16 100)], byte 128, (uint16 4, byte 11))"
|
||||
|
||||
v = g_variant_new_parsed (DATA);
|
||||
g_assert (g_variant_type_equal (g_variant_get_type (v), PERFORMANCE_CONTAINER_TYPEFORMAT));
|
||||
|
||||
/* Ensure data is serialized */
|
||||
serialized_data = g_variant_get_data (v);
|
||||
|
||||
/* Warmup */
|
||||
total = 0;
|
||||
for (i = 0; i < 10; i++)
|
||||
total += sum_gvariant (v);
|
||||
g_assert (total == 10 * 515);
|
||||
|
||||
total = 0;
|
||||
g_timer_start (timer);
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
total += sum_gvariant (v);
|
||||
total += sum_gvariant (v);
|
||||
total += sum_gvariant (v);
|
||||
total += sum_gvariant (v);
|
||||
total += sum_gvariant (v);
|
||||
}
|
||||
g_timer_stop (timer);
|
||||
g_assert (total == 5 * count * 515);
|
||||
|
||||
g_print ("GVariant performance: %.1f kiloiterations per second\n", (count/1000.0)/g_timer_elapsed (timer, NULL));
|
||||
|
||||
c = performance_container_ref_from_variant (v);
|
||||
|
||||
/* Warmup */
|
||||
total = 0;
|
||||
for (i = 0; i < 10; i++)
|
||||
total += sum_generated (c);
|
||||
g_assert (total == 10 * 515);
|
||||
|
||||
g_timer_reset (timer);
|
||||
|
||||
total = 0;
|
||||
g_timer_start (timer);
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
total += sum_generated (c);
|
||||
total += sum_generated (c);
|
||||
total += sum_generated (c);
|
||||
total += sum_generated (c);
|
||||
total += sum_generated (c);
|
||||
}
|
||||
g_timer_stop (timer);
|
||||
g_assert (total == 5 * count * 515);
|
||||
|
||||
g_print ("Generated performance: %.1f kiloiterations per second\n", (count/1000.0)/g_timer_elapsed (timer, NULL));
|
||||
|
||||
return 0;
|
||||
}
|
||||
14
performance.gv
Normal file
14
performance.gv
Normal file
@@ -0,0 +1,14 @@
|
||||
type Container {
|
||||
a: int16;
|
||||
b: int32;
|
||||
c: string;
|
||||
list: 'List [] 'Item {
|
||||
a: int32;
|
||||
b: uint16;
|
||||
};
|
||||
d: byte;
|
||||
tuple : 'Tuple {
|
||||
a: uint16;
|
||||
b: byte;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user