Skip to content

Instantly share code, notes, and snippets.

@otherjoel
Last active March 22, 2021 20:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save otherjoel/1277c6f95686ed0ccdc4cf20c3bd4daa to your computer and use it in GitHub Desktop.
Beeswax/Pollen: simple rendering performance comparison
#lang racket/base
;; Place all the files in this gist in the same folder
;; Then do:
;; racket -tm run-test.rkt -- simple.html.pm out.html template.html.p wax-template.html.rkt
;;
;; For comparison, also try doing "raco make wax-template.html.rkt" before running run-test.rkt
(require pollen/core
(prefix-in pollen: pollen/render))
(provide compare-render main)
(define (compare-render source outfile pollen-template wax-template)
(define in (path->complete-path source))
(define out (path->complete-path outfile))
(define pollen-t (path->complete-path pollen-template))
(displayln "prep: touching source, ensuring doc and metas are cached")
(reset-files in out)
(void (get-doc in)) ; ensures that doc and metas are cached before timing starts
(displayln "\nPollen:")
(time (void (pollen:render-to-file in pollen-t out)))
(displayln "\nBeeswax:")
(time
(void
(let ([render (dynamic-require wax-template 'render)]
[doc (get-doc source)]
[metas (get-metas source)])
(render doc metas (string->symbol outfile))))))
(define (reset-files in out)
;; Reset for clean slate
(with-handlers ([exn:fail:filesystem? (λ (e) (void))])
(delete-file out))
(file-or-directory-modify-seconds in (current-seconds)))
(define (main . args)
(apply compare-render args))
#lang pollen
A very simple document!
<!DOCTYPE html>
<html lang="en">
<head> <title>Pollen</title> </head>
<body>->html[doc]</body>
</html>
#lang beeswax/template
<!DOCTYPE html>
<html lang="en">
<head> <title>Simple!</title> </head>
<body>◊->html[doc]</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment