File: huge-c.e

package info (click to toggle)
entity 1.0.1-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 5,604 kB
  • ctags: 5,394
  • sloc: ansic: 64,242; sh: 7,377; makefile: 776; perl: 319
file content (84 lines) | stat: -rw-r--r-- 1,779 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env entity

<object default-lang="c">
  <timer interval="2000" action="search"/>
  <timer name="create_nodes" interval="1" action="create_nodes"/>
  <system-time/>
  <?c-code
  

#include <sys/types.h>
#include <time.h>

#define NUM_NODES 10000

static char *
thetime (int print_change)
{
    static char buf[1024];
    struct timeval tv;
    static long last_usec;
    
    gettimeofday(&tv, NULL);
    if (print_change) {
	g_snprintf (buf, sizeof (buf), "%d:%d (%f sec ellapsed)", tv.tv_sec, 
		    tv.tv_usec, (tv.tv_usec - last_usec) / 1000000.0);
    } else {
	g_snprintf (buf, sizeof (buf), "%d:%d", tv.tv_sec, 
		    tv.tv_usec);
    }
    last_usec = tv.tv_usec;
    return (buf);
}

EBuf *
search (ENode *timer, GSList *args)
{
    ENode *object;
    GSList *list;
    GSList *tmp;
    int length;
    EBuf *goo;

    g_print ("entering search\n");

    object = enode_parent (timer, "object");
    if (!object)
	return (NULL);

    g_print ("searching nodes..: %s\n", thetime(FALSE));

    goo = ebuf_new_with_str ("goo");
    list = enode_children_attrib (object, "foo", goo);
    ebuf_free (goo);

    length = g_slist_length (list);
    g_print ("returned %d nodes: %s\n", length, thetime(TRUE));
    return (NULL);
}

EBuf *
create_nodes (ENode *timer, GSList *args)
{
    ENode *object;
    ENode *node;
    gint i;

    object = enode_parent (timer, "object");
    g_print ("building %d nodes...: %s\n", NUM_NODES, thetime(FALSE));

    for (i = 0; i < NUM_NODES; i++) {
	node = enode_new_child (object, "fooey", NULL);
	if (! (i % 2)) {
	    enode_attrib (node, "foo", ebuf_new_with_str ("goo"));
	}
    }

    g_print ("done: %s\n", thetime (TRUE));

    enode_attrib (timer, "interval", ebuf_new_with_str ("-1"));
    return (NULL);
}

?>
</object>