-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
executable file
·82 lines (71 loc) · 1.99 KB
/
test.py
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
#!/usr/bin/env python
import random
from rgr import Graph
import string
import sys
def make_random_kwargs():
kwargs = {}
namevalue = []
for v in range(random.randint(5,20)):
namevalue.append(random.choice(string.letters+"_:' 0123456789"))
kwargs['name'] = ''.join(namevalue)
for i in range(random.randint(3,5)):
key = []
value = []
key.append(random.choice(string.letters))
for k in range(random.randint(2,16)):
#key.append(random.choice(string.letters))
key.append(random.choice(string.letters+"_0123456789"))
for v in range(random.randint(5,20)):
#value.append(random.choice(string.letters))
value.append(random.choice(string.letters+"_:' 0123456789"))
kwargs[''.join(key)] = ''.join(value)
return kwargs
def dump_everything():
print '===================='
print
print "nodes:", g.nodes()
print "edges:", g.edges()
print "leftovers:"
for k in g.redis.keys(): print k
print
print '===================='
for n in g.nodes():
print "---"
print 'id', n.id
print 'properties:', n.properties()
print "*******"
for e in g.edges():
print "---"
print 'id', e.id
print 'properties:', e.properties()
"""
nodes_to_create = 100000
edges_to_create = 500000
ri = random.randint
g = Graph()
g.redis.flushdb()
g = Graph()
print "creating nodes"
for i in xrange(nodes_to_create):
g.add_node(**make_random_kwargs())
sys.stdout.write('.')
sys.stdout.flush()
print "creating edges"
for i in xrange(edges_to_create):
g.add_edge(ri(0, nodes_to_create-1),ri(0, nodes_to_create-1),**make_random_kwargs())
sys.stdout.write('.')
sys.stdout.flush()
#dump_everything()
print "testing search"
for n in g.find_nodes(name="jo"):
print n.properties()
print
"""
#dump_everything()
g = Graph()
print 'deleting all nodes:'
for n in g.nodes():
g.del_node(n)
sys.stdout.write('.')
sys.stdout.flush()