Last active
March 22, 2021 20:25
-
-
Save otherjoel/1277c6f95686ed0ccdc4cf20c3bd4daa to your computer and use it in GitHub Desktop.
Beeswax/Pollen: simple rendering performance comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang pollen | |
A very simple document! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> <title>Pollen</title> </head> | |
<body>◊->html[doc]</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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