Skip to content

Instantly share code, notes, and snippets.

@axiak
Created Mar 16, 2017
Embed
What would you like to do?
#!/usr/bin/env
import numpy as np
import random
import quopri
lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed porta varius vulputate. Nullam ultricies consequat iaculis. Mauris vulputate diam lacus, sit amet pharetra elit volutpat nec. Vivamus lectus arcu, facilisis ac varius in, imperdiet nec libero. Nulla pellentesque purus id iaculis placerat. Phasellus nec dapibus diam. Mauris vel accumsan ex, non imperdiet justo. Maecenas at ligula fringilla, molestie lorem eget, cursus lacus. Nulla luctus ornare ipsum. Pellentesque vitae commodo nulla. Cras finibus luctus arcu et porttitor.Donec vel neque sed elit bibendum sodales. In ultricies enim nec elit posuere tincidunt. Aliquam nec ante et lectus varius aliquam. Etiam in finibus diam. Maecenas non nulla id purus tincidunt interdum non nec neque. Integer rhoncus quam non congue tempus. Maecenas non rhoncus quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam id fringilla nibh. Nulla quis diam a nisi vestibulum consequat. Vivamus id dolor sed metus ullamcorper aliquam non sit amet quam. Mauris sodales commodo blandit. In sit amet mauris vitae mi malesuada scelerisque.Praesent sed efficitur neque, a hendrerit erat. Vivamus pulvinar nisl ante, id hendrerit enim suscipit ut. In sit amet sem lobortis, efficitur eros quis, viverra ipsum. Cras fringilla quis ipsum sit amet egestas. Morbi tincidunt felis nec elit pulvinar, ac fringilla nulla fermentum. Aliquam feugiat sodales tortor ut feugiat. Cras fringilla ut velit dignissim lobortis.Praesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor etVesPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesent lacinia dolor et turpis eleifend, quis ullaPraesbero, commodo non lacus imperdiet, eleifend blandit odio. Integer a pellentesque risus, et sollicitudin eros. Nam in ultricies enim. Quisque placerat rutrum purus ac consectetur. In ex arcu, ornare sit amet mattis eleifend, lobortis nec dui. Aenean congue eleifend urna, et pretium dolor varius sed. Ut rutrum ullamcorper mi vitae sagittis. Sed ipsum purus, convallis in semper quis, pretium sed tellus. In non luctus velit, a molestie diam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.'
chinese = u'\u81ea\u79f0\u9ad8\u5b87\u4ec1\uff08\u53d7\u8bbf\u8005\u4e0d\u613f\u900f\u9732\u771f\u5b9e\u59d3\u540d\uff09\u7684\u4e00\u540d\u4e2d\u56fd\u7559\u7f8e\u5973\u5b66\u751f\uff0c2\u670827\u65e5\u4ece\u5e7f\u5dde\u98de\u62b5\u6d1b\u6749\u77f6\u56fd\u9645\u673a\u573a\u540e\uff0c\u5148\u88ab\u8054\u90a6\u6d77\u5173\u66a8\u8fb9\u5883\u4fdd\u62a4\u5c40\u6263\u7559\u3001\u8be2\u95ee\u4e8630\u4f59\u5c0f\u65f6\uff0c\u968f\u540e\u4fbf\u5c06\u5176\u9063\u9001\u56de\u56fd\u4e86\u3002\u4e8b\u540e\u9ad8\u5b87\u4ec1\u5728\u7f51\u4e0a\u516c\u5e03\u4e86\u5979\u7684\u8fd9\u6bb5\u906d\u9047\uff0c\u5f15\u8d77\u5e7f\u6cdb\u5173\u6ce8\u3002\u7f51\u4e0a\u4e5f\u6709\u4e0d\u5c11\u5a92\u4f53\u501f\u673a\u7092\u4f5c\uff0c\u628a\u4e8b\u60c5\u95f9\u5f97\u6cb8\u6cb8\u626c\u626c\u3002\u5c31\u6b64\uff0c\u4fa8\u62a5\u8bb0\u8005\u8054\u7cfb\u5230\u672c\u4eba\uff0c\u4e13\u95e8\u8fdb\u884c\u4e86\u7535\u8bdd\u91c7\u8bbf\u3002\u4ee5\u4e0b\u662f\u4fa8\u62a5\u8bb0\u8005\u72ec\u5bb6\u8d8a\u6d0b\u7535\u8bdd\u91c7\u8bbf\u5185\u5bb9\u3002\u9ad8\u5b87\u4ec1\u8bf4\uff0c\u5979\u5e76\u4e0d\u60f3\u535a\u5f97\u540c\u60c5\uff0c\u5979\u63a5\u53d7\u91c7\u8bbf\u7684\u53e6\u4e00\u76ee\u7684\u662f\uff0c\u8ba9\u90a3\u4e9b\u5df2\u5728\u7f8e\u56fd\u7559\u5b66\u7684\uff0c\u6216\u5c06\u8981\u5230\u7f8e\u56fd\u7559\u5b66\u7684\u4e2d\u56fd\u5b66\u751f\u80fd\u4ece\u5176\u7ecf\u5386\u4e2d\u5438\u53d6\u6559\u8bad\uff0c\u9047\u4e8b\u4e0d\u614c\uff0c\u4e0d\u8981\u50cf\u5979\u90a3\u6837\u8499\u53d7\u4e0d\u767d\u4e4b\u51a4\u3002\u88ab\u9063\u8fd4\u4e00\u4e8b\u5bf9\u5979\u6253\u51fb\u5f88\u5927\uff0c\u5979\u5bb6\u4eba\u4e5f\u540c\u6837\u53d7\u5230\u4e86\u91cd\u5927\u6253\u51fb\u3002\u201c\u73b0\u5728\u6211\u4e0d\u592a\u613f\u610f\u4e0e\u4eba\u89c1\u9762\u3001\u4ea4\u6d41\uff0c\u6bcf\u5929\u665a\u4e0a\u7761\u7720\u4e5f\u4e0d\u597d\uff0c\u4e00\u70b9\u70b9\u98ce\u5439\u8349\u52a8\u5c31\u80fd\u9192\uff0c\u7279\u522b\u654f\u611f\u3002\u4e0d\u592a\u613f\u610f\u542c\u5230\u624b\u673a\u7684\u58f0\u97f3\uff0c\u5305\u62ec\u522b\u4eba\u7684\u548c\u6211\u81ea\u5df1\u7684\uff0c\u603b\u89c9\u5f97\u54cd\u4e86\u4ee5\u540e\u5c31\u6709\u4e8b\uff0c\u4e0d\u60f3\u770b\u89c1\uff0c\u4e0d\u60f3\u542c\u89c1\u3002\u4ece\u4e8b\u4ef6\u53d1\u751f\u540e\u5230\u73b0\u5728\u5c31\u6ca1\u6709\u597d\u597d\u5403\u8fc7\u51e0\u53e3\u996d\uff0c\u6ca1\u4ec0\u4e48\u80c3\u53e3\u3002\u201d'
emojis = u'\U0001f600\U0001f601\U0001f602\U0001f923\U0001f603\U0001f604\U0001f605\U0001f606\U0001f609\U0001f60a\U0001f60b\U0001f60e\U0001f60d\U0001f618\U0001f617\U0001f619\U0001f61a\u263a\ufe0f\U0001f642\U0001f917\U0001f914\U0001f610\U0001f611\U0001f636\U0001f644\U0001f60f\U0001f623\U0001f625\U0001f62e\U0001f910\U0001f62f\U0001f62a\U0001f62b\U0001f634\U0001f60c\U0001f61b\U0001f61c\U0001f61d\U0001f924\U0001f612\U0001f613\U0001f614\U0001f615\U0001f643\U0001f911\U0001f632\u2639\ufe0f\U0001f641\U0001f616\U0001f61e\U0001f61f\U0001f624\U0001f622\U0001f62d\U0001f626\U0001f627\U0001f628\U0001f629\U0001f62c\U0001f630\U0001f631\U0001f633\U0001f635\U0001f621\U0001f620\U0001f637\U0001f912\U0001f915\U0001f922\U0001f927\U0001f607\U0001f920\U0001f921\U0001f925\U0001f913\U0001f608\U0001f47f\U0001f479\U0001f47a\U0001f480\U0001f47b\U0001f47d\U0001f916\U0001f4a9\U0001f63a\U0001f638\U0001f639\U0001f63b\U0001f63c\U0001f63d\U0001f640\U0001f63f\U0001f63e\U0001f476\U0001f466\U0001f467\U0001f468\U0001f469\U0001f474\U0001f475\U0001f468\u200d\u2695\ufe0f\U0001f469\u200d\u2695\ufe0f\U0001f468\u200d\U0001f393\U0001f469\u200d\U0001f393\U0001f468\u200d\u2696\ufe0f\U0001f469\u200d\u2696\ufe0f\U0001f468\u200d\U0001f33e\U0001f469\u200d\U0001f33e\U0001f468\u200d\U0001f373\U0001f469\u200d\U0001f373\U0001f468\u200d\U0001f527\U0001f469\u200d\U0001f527\U0001f468\u200d\U0001f3ed\U0001f469\u200d\U0001f3ed\U0001f468\u200d\U0001f4bc\U0001f469\u200d\U0001f4bc\U0001f468\u200d\U0001f52c\U0001f469\u200d\U0001f52c\U0001f468\u200d\U0001f4bb\U0001f469\u200d\U0001f4bb\U0001f468\u200d\U0001f3a4\U0001f469\u200d\U0001f3a4\U0001f468\u200d\U0001f3a8\U0001f469\u200d\U0001f3a8\U0001f468\u200d\u2708\ufe0f\U0001f469\u200d\u2708\ufe0f\U0001f468\u200d\U0001f680\U0001f469\u200d\U0001f680\U0001f468\u200d\U0001f692\U0001f469\u200d\U0001f692\U0001f46e\U0001f46e\u200d\u2642\ufe0f\U0001f46e\u200d\u2640\ufe0f\U0001f575\ufe0f\U0001f575\ufe0f\u200d\u2642\ufe0f\U0001f575\ufe0f\u200d\u2640\ufe0f\U0001f482\U0001f482\u200d\u2642\ufe0f\U0001f482\u200d\u2640\ufe0f\U0001f477\U0001f477\u200d\u2642\ufe0f\U0001f477\u200d\u2640\ufe0f\U0001f934\U0001f478\U0001f473\U0001f473\u200d\u2642\ufe0f\U0001f473\u200d\u2640\ufe0f\U0001f472\U0001f471\U0001f471\u200d\u2642\ufe0f\U0001f471\u200d\u2640\ufe0f\U0001f935\U0001f470\U0001f930\U0001f47c\U0001f385\U0001f936\U0001f64d\U0001f64d\u200d\u2642\ufe0f\U0001f64d\u200d\u2640\ufe0f\U0001f64e\U0001f64e\u200d\u2642\ufe0f\U0001f64e\u200d\u2640\ufe0f\U0001f645\U0001f645\u200d\u2642\ufe0f\U0001f645\u200d\u2640\ufe0f\U0001f646\U0001f646\u200d\u2642\ufe0f\U0001f646\u200d\u2640\ufe0f\U0001f481\U0001f481\u200d\u2642\ufe0f\U0001f481\u200d\u2640\ufe0f\U0001f64b\U0001f64b\u200d\u2642\ufe0f\U0001f64b\u200d\u2640\ufe0f\U0001f647\U0001f647\u200d\u2642\ufe0f\U0001f647\u200d\u2640\ufe0f\U0001f926\U0001f926\u200d\u2642\ufe0f\U0001f926\u200d\u2640\ufe0f\U0001f937\U0001f937\u200d\u2642\ufe0f\U0001f937\u200d\u2640\ufe0f\U0001f486\U0001f486\u200d\u2642\ufe0f\U0001f486\u200d\u2640\ufe0f\U0001f487\U0001f487\u200d\u2642\ufe0f\U0001f487\u200d\u2640\ufe0f\U0001f6b6\U0001f6b6\u200d\u2642\ufe0f\U0001f6b6\u200d\u2640\ufe0f\U0001f3c3\U0001f3c3\u200d\u2642\ufe0f\U0001f3c3\u200d\u2640\ufe0f\U0001f483\U0001f57a\U0001f46f\U0001f46f\u200d\u2642\ufe0f\U0001f46f\u200d\u2640\ufe0f\U0001f574\ufe0f\U0001f5e3\ufe0f\U0001f464\U0001f465\U0001f46b\U0001f46c\U0001f46d\U0001f48f\U0001f468\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f468\U0001f469\u200d\u2764\ufe0f\u200d\U0001f48b\u200d\U0001f469\U0001f491\U0001f468\u200d\u2764\ufe0f\u200d\U0001f468\U0001f469\u200d\u2764\ufe0f\u200d\U0001f469\U0001f46a\U0001f468\u200d\U0001f469\u200d\U0001f466\U0001f468\u200d\U0001f469\u200d\U0001f467\U0001f468\u200d\U0001f469\u200d\U0001f467\u200d\U0001f466\U0001f468\u200d\U0001f469\u200d\U0001f466\u200d\U0001f466\U0001f468\u200d\U0001f469\u200d\U0001f467\u200d\U0001f467\U0001f468\u200d\U0001f468\u200d\U0001f466\U0001f468\u200d\U0001f468\u200d\U0001f467\U0001f468\u200d\U0001f468\u200d\U0001f467\u200d\U0001f466\U0001f468\u200d\U0001f468\u200d\U0001f466\u200d\U0001f466\U0001f468\u200d\U0001f468\u200d\U0001f467\u200d\U0001f467\U0001f469\u200d\U0001f469\u200d\U0001f466\U0001f469\u200d\U0001f469\u200d\U0001f467\U0001f469\u200d\U0001f469\u200d\U0001f467\u200d\U0001f466\U0001f469\u200d\U0001f469\u200d\U0001f466\u200d\U0001f466\U0001f469\u200d\U0001f469\u200d\U0001f467\u200d\U0001f467\U0001f468\u200d\U0001f466\U0001f468\u200d\U0001f466\u200d\U0001f466\U0001f468\u200d\U0001f467\U0001f468\u200d\U0001f467\u200d\U0001f466\U0001f468\u200d\U0001f467\u200d\U0001f467\U0001f469\u200d\U0001f466\U0001f469\u200d\U0001f466\u200d\U0001f466\U0001f469\u200d\U0001f467\U0001f469\u200d\U0001f467\u200d\U0001f466\U0001f469\u200d\U0001f467\u200d\U0001f467\U0001f933\U0001f4aa\U0001f448\U0001f449\u261d\ufe0f\U0001f446\U0001f595\U0001f447\u270c\ufe0f\U0001f91e\U0001f596\U0001f918\U0001f590\ufe0f\u270b\U0001f44c\U0001f44d\U0001f44e\u270a\U0001f44a\U0001f91b\U0001f91c\U0001f91a\U0001f44b\u270d\ufe0f\U0001f44f\U0001f450\U0001f64c\U0001f64f\U0001f91d\U0001f485\U0001f442\U0001f443\U0001f463\U0001f440\U0001f441\ufe0f\U0001f445\U0001f444\U0001f48b\U0001f453\U0001f576\ufe0f\U0001f454\U0001f455\U0001f456\U0001f457\U0001f458\U0001f459\U0001f45a\u2019\U0001f45b\U0001f45c\U0001f45d\U0001f392\U0001f45e\u2019\U0001f45f\U0001f460\U0001f461\u2019\U0001f462\u2019\U0001f451\U0001f452\u2019\U0001f3a9\U0001f393\u26d1\ufe0f\u2019\U0001f484\U0001f48d\U0001f302\u2602\ufe0f\U0001f4bc'
def generate_frac(nonascii=0.1, n=1024):
return (u''.join(random.choice(lorem)
for _ in range(int(n * (1 - nonascii)))) +
u''.join(random.choice(chinese)
for _ in range(int(n * nonascii * .5))) +
u''.join(random.choice(emojis)
for _ in range(int(n * nonascii * .5)))
)
def measure_frac(nonascii=0.1, iter=100):
qp = []
b64 = []
for i in range(iter):
source = generate_frac(nonascii)
qp.append(len(quopri.encodestring(source.encode('utf8'))))
b64.append(len(source.encode('utf8').encode('base64')))
return np.mean(qp), np.mean(b64)
def main():
for frac in (0.05, 0.1, 0.16666, 0.2, 0.5):
qp, b64 = measure_frac(frac)
print "{}: qp={}; b64={}".format(
frac,
qp,
b64
)
if __name__ == '__main__':
main()
@axiak

This comment has been minimized.

Copy link
Owner Author

@axiak axiak commented Mar 16, 2017

Here's the output:

0.05: qp=1435.58; b64=1507.64
0.1: qp=1837.86; b64=1638.84
0.16666: qp=2367.3; b64=1809.8
0.2: qp=2629.86; b64=1893.92
0.5: qp=5010.36; b64=2663.32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment