ruby 10 000 000

 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
#!/usr/bin/env python
# coding: utf-8
from itertools import groupby
log = [
{"time": 201201, "x": 2},
{"time": 201201, "y": 7},
{"time": 201201, "z": 2},
{"time": 201202, "a": 3},
{"time": 201202, "b": 4},
{"time": 201202, "c": 0}
]
import string
import random
def gen_ten_m():
for x in xrange(1000*1000):
yield {'time': random.randint(201200,201222),
random.choice(string.letters): 1}
def transmogify(data):
res = []
for k, g in groupby(data, lambda d: d['time']):
d = {'time': k}
for dic in g:
d.update(dic)
res.append(d)
return res
print(len(transmogify(gen_ten_m())))
#[
# {time: 201201, x: 2, y: 7, z: 2},
# {time: 201202, a: 3, b: 4, c: 0},
#]