Skip to content

Instantly share code, notes, and snippets.

@gsauthof
Last active February 12, 2017 16:27
Show Gist options
  • Save gsauthof/e2787adc7e9a46811dcb6aff2054110c to your computer and use it in GitHub Desktop.
Save gsauthof/e2787adc7e9a46811dcb6aff2054110c to your computer and use it in GitHub Desktop.
Costs of ordered attributes in generated feeds
# in reply to: https://groups.google.com/d/msg/django-developers/6mm42rrQXww/Yee5KJjVBQAJ
# (pull request: write feeds with ordered attributes)
# cf. https://github.com/django/django/pull/8044
#
# Results:
# - generating one feed: ~ 0.01 s (current Laptop, i7, SSD)
# - sorting + OrderedDict() in SimpleXMLGenerator::startElement(): + ~ 27 %
# - sorting + OrderedDict() iff there are attributes: + ~ 18 %
# - replacing {} with [] for attributes in feedgenerator: + ~ 7 %
from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed
import datetime
import timeit
feed_class = Rss201rev2Feed
feed_class = Atom1Feed
def gen_feed():
feed = feed_class(title='The Site',
link='https://example.org/',
feed_url='https://example.org/feed.xml',
description='blah blub')
for i in range(100):
feed.add_item(title='some entry', link='https://example.org/{}'.format(i),
unique_id='{}'.format(i),
description='''Lorem ipsum
From Wikipedia, the free encyclopedia
"Ipsum" redirects here. For the car, see Toyota Ipsum.
"Random text" redirects here. It is not to be confused with Random text generator.
This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (April 2012) (Learn how and when to remove this template message)
Using lorem ipsum to focus attention on graphic elements in a webpage design proposal
In publishing and graphic design, lorem ipsum (derived from Latin dolorem ipsum, translated as "pain itself") is a filler text commonly used to demonstrate the graphic elements of a document or visual presentation. Replacing meaningful content with placeholder text allows designers to design the form of the content before the content itself has been produced.[citation needed]
The lorem ipsum text is typically a scrambled section of De finibus bonorum et malorum, a 1st-century BC Latin text by Cicero, with words altered, added, and removed to make it nonsensical, improper Latin.[citation needed]
A variation of the ordinary lorem ipsum text has been used in typesetting since the 1960s or earlier, when it was popularized by advertisements for Letraset transfer sheets. It was introduced to the Information Age in the mid-1980s by Aldus Corporation, which employed it in graphics and word-processing templates for its desktop publishing program PageMaker.[1][not in citation given]
Contents
1 Example text
2 Discovery
3 Latin source
4 English translation
5 Variations
6 See also
7 Notes
8 References
9 External links
Example text
A common form of lorem ipsum reads:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Discovery
Page break in Rackham (Loeb) edition of Cicero De Finibus showing origin of lorem ipsum from hyphenation of dolorem ipsum
"Lorem ipsum" text is derived from sections 1.10.33 of Cicero's De finibus bonorum et malorum.[2]
It is not known exactly when the text obtained its current standard form; it may have been as late as the 1960s. Dr. Richard McClintock, a Latin scholar who was the publications director at Hampden–Sydney College in Virginia, discovered the source of the passage sometime before 1982 while searching for instances of the Latin word "consectetur", rarely used in classical literature.[1][a] The physical source of the Lorem Ipsum text may be the 1914 Loeb Classical Library Edition of the De Finibus, where the Latin text finishes page 34 with "Neque porro quisquam est qui do-" and begins page 36 with "lorem ipsum (et seq.)…", suggesting that the galley type of that page 36 was mixed up to make the dummy text seen today.[citation needed]
''',
categories=['intersting', 'stuff'],
author_name='John Doe',
pubdate=datetime.date(2017, 1, 23))
with open('t.xml', 'w') as f:
feed.write(f, 'utf-8')
print(timeit.repeat(gen_feed, number=1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment