Changeset 316:8b6a594b3761

Show
Ignore:
Timestamp:
2007-09-02 16:36:05 (1 year ago)
Author:
Stefan Schwarzer <sschwarzer@sschwarzer.net>
branch:
default
Message:
Added some code to test the effect on render time when
syntax-highlighted pages rendered by Pygments are cached.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • browser.py

    r298 r316  
    3030import os 
    3131import sys 
     32import time 
    3233import urllib 
    3334import urlparse 
     
    103104                self.emit_data(data=self.get_file(source_path, raw=True), 
    104105                               content_type=content_type) 
     106 
    105107    # 
    106108    # HTTP-specific processing 
     
    171173        Handle HTTP GET request. 
    172174        """ 
     175        start_time = time.time() 
     176        self._time = None 
    173177        # reject forbidden clients 
    174178        if config.allowed_clients is not config.ALL_CLIENTS and \ 
     
    231235                       h1_class=h1_class, 
    232236                       use_header_and_footer=use_header_and_footer) 
     237        print "Render time:", time.time() - start_time, "s" 
    233238 
    234239    # 
  • converter.py

    r315 r316  
    199199    return u"\n".join(('<pre>', cgi.escape(text), '</pre>')) 
    200200 
    201 def text_to_html(text, path): 
     201def text_to_html(text, path, _cache={}): 
    202202    """ 
    203203    Convert the unicode string `text` to HTML and return the HTML 
     
    207207    if not pygmentsfinder.found_pygments: 
    208208        return dumb_text_to_html(text) 
     209    #TODO make cache handling threadsafe when Websourcebrowser 
     210    #  works multithreaded 
     211    if (text, path) in _cache: 
     212        return _cache[text, path] 
    209213    try: 
    210214        # assume the link doesn't point to a link or at least has 
     
    222226    formatter = pygmentsfinder.formatters.HtmlFormatter( 
    223227                linenos=config.line_numbers) 
    224     return pygmentsfinder.pygments.highlight(text, lexer, formatter) 
     228    html = pygmentsfinder.pygments.highlight(text, lexer, formatter) 
     229    _cache[text, path] = html 
     230    return html 
    225231 
    226232def image_to_html(url):