Current File : //usr/share/doc/python-jinja2-2.7.2/examples/rwbench/rwbench.py
# -*- coding: utf-8 -*-
"""
    RealWorldish Benchmark
    ~~~~~~~~~~~~~~~~~~~~~~

    A more real-world benchmark of Jinja2.  Like the other benchmark in the
    Jinja2 repository this has no real-world usefulnes (despite the name).
    Just go away and ignore it.  NOW!

    :copyright: (c) 2009 by the Jinja Team.
    :license: BSD.
"""
import sys
from os.path import join, dirname, abspath
try:
    from cProfile import Profile
except ImportError:
    from profile import Profile
from pstats import Stats
ROOT = abspath(dirname(__file__))

from random import choice, randrange
from datetime import datetime
from timeit import Timer
from jinja2 import Environment, FileSystemLoader
from jinja2.utils import generate_lorem_ipsum
from mako.lookup import TemplateLookup
from genshi.template import TemplateLoader as GenshiTemplateLoader


def dateformat(x):
    return x.strftime('%Y-%m-%d')


jinja_env = Environment(loader=FileSystemLoader(join(ROOT, 'jinja')))
jinja_env.filters['dateformat'] = dateformat
mako_lookup = TemplateLookup(directories=[join(ROOT, 'mako')])
genshi_loader = GenshiTemplateLoader([join(ROOT, 'genshi')])

class Article(object):

    def __init__(self, id):
        self.id = id
        self.href = '/article/%d' % self.id
        self.title = generate_lorem_ipsum(1, False, 5, 10)
        self.user = choice(users)
        self.body = generate_lorem_ipsum()
        self.pub_date = datetime.utcfromtimestamp(randrange(10 ** 9, 2 * 10 ** 9))
        self.published = True


class User(object):

    def __init__(self, username):
        self.href = '/user/%s' % username
        self.username = username


users = map(User, [u'John Doe', u'Jane Doe', u'Peter Somewhat'])
articles = map(Article, range(20))
navigation = [
    ('index',           'Index'),
    ('about',           'About'),
    ('foo?bar=1',       'Foo with Bar'),
    ('foo?bar=2&s=x',   'Foo with X'),
    ('blah',            'Blub Blah'),
    ('hehe',            'Haha'),
] * 5

context = dict(users=users, articles=articles, page_navigation=navigation)


jinja_template = jinja_env.get_template('index.html')
mako_template = mako_lookup.get_template('index.html')
genshi_template = genshi_loader.load('index.html')


def test_jinja():
    jinja_template.render(context)

def test_mako():
    mako_template.render_unicode(**context)


from djangoext import django_loader, DjangoContext
def test_django():
    # not cached because django is not thread safe and does
    # not cache by itself so it would be unfair to cache it here.
    django_template = django_loader.get_template('index.html')
    django_template.render(DjangoContext(context))


def test_genshi():
    genshi_template.generate(**context).render('html', doctype='html')


if __name__ == '__main__':
    sys.stdout.write('Realworldish Benchmark:\n')
    for test in 'jinja', 'mako', 'django', 'genshi':
        t = Timer(setup='from __main__ import test_%s as bench' % test,
                  stmt='bench()')
        sys.stdout.write(' >> %-20s<running>' % test)
        sys.stdout.flush()
        sys.stdout.write('\r    %-20s%.4f seconds\n' % (test, t.timeit(number=200) / 200))

    if '-p' in sys.argv:
        print 'Jinja profile'
        p = Profile()
        p.runcall(test_jinja)
        stats = Stats(p)
        stats.sort_stats('time', 'calls')
        stats.print_stats()
blog

blog

1Win официальный сайт букмекера — 1Вин ставки на спорт.3925

1Win официальный сайт букмекера — 1Вин ставки на спорт ▶️ ИГРАТЬ Содержимое 1Win – Официальный Сайт Букмекера Преимущества и Функции 1Win Преимущества для клиентов Как сделать Ставку на Спорт Бонусы и Акции 1Win Бонусы для новых игроков Акции и промокоды Отзывы и Рейтинг В мире ставок на спорт есть много …

Read More »

Betify Casino en Ligne Jouez sur Betify avec 1000 €.3455

Betify Casino en Ligne | Jouez sur Betify avec 1000 € ▶️ JOUER Содержимое Créez votre compte Betify et commencez à jouer avec 1000 € La création du compte Betify La connexion à Betify Les avantages de Betify Les avis sur Betify Les paris sportifs sur Betify Betify Casino en …

Read More »

Betify Casino Avis & Bonus exclusif (2025).451

Betify Casino – Avis & Bonus exclusif (2025) ▶️ JOUER Содержимое Qu’est-ce que Betify Casino ? Les avantages de jouer à Betify Casino Une application de jeu de haute qualité Un choix de jeux varié et riche Un bonus de bienvenue attrayant Une connexion sécurisée et fiable Vous cherchez un …

Read More »

Glory Casino Bangladesh Official Website.204 (2)

Glory Casino Bangladesh Official Website ▶️ PLAY Содержимое Experience the Thrill of Online Gaming Secure and Reliable Online Casino Platform Glory Casino’s Commitment to Security Glory Casino’s Reliable Online Casino Platform Are you ready to experience the thrill of online gaming like never before? Look no further than the Glory …

Read More »

Casino Mostbet Azərbaycan.338

Casino Mostbet Azərbaycan ▶️ OYNA Содержимое Mostbet-də Onlayn Rulet və Poker Oyunları Onlayn Rulet Oyunları Mostbet Azərbaycan-da Qeydiyyat və İdman Mərcləri Mostbet Casino-da Slot Maşın və Jackpot Oyunları Slot Maşın Oyunları Mostbet Azərbaycanın ən məşhur onlayn kazinolarından biridir. mostbet az qeydiyyat prosesi çox asandır və istifadəçilər mostbet.com saytına daxil olaraq …

Read More »

– Официальный сайт Pinco Casino.907

Пинко Казино – Официальный сайт Pinco Casino ▶️ ИГРАТЬ Содержимое Преимущества игры на официальном сайте Pinco Casino Безопасность и надежность Великая выборка игр Виды игр и слотов на официальном сайте Pinco Casino Бонусы и акции на официальном сайте Pinco Casino Как начать играть на официальном сайте Pinco Casino Шаг 1: …

Read More »

– Официальный сайт Pinco Casino.769

Пинко Казино – Официальный сайт Pinco Casino ▶️ ИГРАТЬ Содержимое Преимущества игроков в Pinco Casino Возможности для игроков Большой выбор игр Бонусы и акции В современном мире азартных игр, где каждый день появляются новые онлайн-казино, найти достоверный и надежный игрок может быть сложной задачей. Однако, если вы ищете официальный сайт …

Read More »

Gioco Plinko nei casinò online in Italia.521

Gioco Plinko nei casinò online in Italia ▶️ GIOCARE Содержимое Le caratteristiche del gioco Le caratteristiche del gioco Plinko Le strategie per vincere al Gioco Plinko Capire il gioco Conclusione Le migliori opzioni per giocare online Il gioco Plinko è un fenomeno del mondo dei casinò online, che ha conquistato …

Read More »

Meilleur Casino en Ligne 2025 – Sites Fiables.13815

Meilleur Casino en Ligne 2025 – Sites Fiables ▶️ JOUER Содержимое Les Meilleurs Casinos en Ligne pour les Joueurs Français Comment Choisir un Casino en Ligne Fiable Les Avantages et les Inconvénients des Casinos en Ligne Les conseils pour jouer responsable Les Meilleurs Bonus de Bienvenue pour les Joueurs Français …

Read More »

Top 10 Casinos en Ligne (2025) – Sites Fiables & Légaux.12731

Top 10 Casinos en Ligne (2025) – Sites Fiables & Légaux ▶️ JOUER Содержимое Les Meilleurs Casinos en Ligne (2025) – Sites Fiables & Légaux Les Casinos en Ligne les Plus Populaires Les Casinos en Ligne les Plus Fiables Meilleur Casino en Ligne Les Casinos en Ligne les Plus Légaux …

Read More »