This repository has been archived by the owner on Nov 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmeasure_memory.py
103 lines (76 loc) · 2.91 KB
/
measure_memory.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:mod:`timeit`
=======================
.. moduleauthor:: hbldh <henrik.blidh@swedwise.com>
Created on 2016-05-20, 13:28
"""
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import
import os
from xmlr import xmlparse, xmliter, XMLParsingMethods
def document_size(doc):
"""A storage size estimator.
:param doc: The document or list of documents to find size of.
:type doc: dict or list
:return: The size of the input document(s) in bytes.
:rtype: int
"""
import sys
import datetime
size = 0
if isinstance(doc, (list, tuple)):
size += int(sum([document_size(d) for d in doc]))
elif isinstance(doc, dict):
for k in doc:
size += document_size(doc[k])
elif isinstance(doc, (datetime.datetime, float, int, long, basestring)):
size += sys.getsizeof(doc)
elif doc is None:
pass
else:
raise ValueError("Unsizable object: {0}".format(type(doc)))
return size
filepath = '/home/hbldh/Downloads/google-renewals-all-20080624.xml'
#print('Size in MB: {0:.2f} MB'.format(document_size(doc)/1024./1024.))
"""
"""
# xmlparse
print ('xmlr.xmlparse using xml.etree.ElementTree')
doc = xmlparse("/home/hbldh/Downloads/google-renewals-all-20080624.xml", XMLParsingMethods.ELEMENTTREE)
print('Size in MB: {0:.2f} MB'.format(document_size(doc)/1024./1024.))
del doc
print ('xmlr.xmlparse using xml.etree.cElementTree')
doc = xmlparse("/home/hbldh/Downloads/google-renewals-all-20080624.xml", XMLParsingMethods.C_ELEMENTTREE)
print('Size in MB: {0:.2f} MB'.format(document_size(doc)/1024./1024.))
del doc
print ('xmlr.xmlparse using lxml.etree')
doc = xmlparse("/home/hbldh/Downloads/google-renewals-all-20080624.xml", XMLParsingMethods.LXML_ELEMENTTREE)
print('Size in MB: {0:.2f} MB'.format(document_size(doc)/1024./1024.))
del doc
# xmliter
print ('xmlr.xmliter using xml.etree.ElementTree')
docs = []
for d in xmliter("/home/hbldh/Downloads/google-renewals-all-20080624.xml", "Record", XMLParsingMethods.ELEMENTTREE):
docs.append(d)
print('Size in MB: {0:.2f} MB'.format(document_size(docs)/1024./1024.))
del docs
print ('xmlr.xmliter using xml.etree.cElementTree')
docs = []
for d in xmliter("/home/hbldh/Downloads/google-renewals-all-20080624.xml", "Record", XMLParsingMethods.C_ELEMENTTREE):
docs.append(d)
print('Size in MB: {0:.2f} MB'.format(document_size(docs)/1024./1024.))
del docs
print ('xmlr.xmliter using lxml.etree')
docs = []
for d in xmliter("/home/hbldh/Downloads/google-renewals-all-20080624.xml", "Record", XMLParsingMethods.LXML_ELEMENTTREE):
docs.append(d)
print('Size in MB: {0:.2f} MB'.format(document_size(docs)/1024./1024.))
del docs
# Straight parsing
#print ('lxml.parse')
#import lxml.etree as etree
#doc = etree.parse("/home/hbldh/Downloads/google-renewals-all-20080624.xml")