<commit_before>#|
  This file is a part of clta project.
  Copyright (c) 2014 κeen
|#

(in-package :cl-user)
(defpackage clta-bench
  (:use
   :cl
   :clta)
  (:import-from :fast-io
   :with-fast-output))
(in-package :clta-bench)

(defparameter *templates* '("simple.tmpl"))

(defmacro bench1000000 (form)
  `(time (loop :repeat 1000000 :do ,form)))

(defun bench/clta (tmpl)
  (let ((stream-renderer (compile-template-file (make-backend :stream) tmpl ()))
        (octet-stream-renderer (compile-template-file (make-backend :octet-stream) tmpl ()))
        (string-renderer (compile-template-file (make-backend :string) tmpl ()))
        (octets-renderer (compile-template-file (make-backend :octets) tmpl ()))
        (fast-io-renderer (compile-template-file (make-backend :fast-io) tmpl ()))
        (/dev/null (make-broadcast-stream)))
    (bench1000000 (funcall stream-renderer /dev/null))
    (bench1000000 (funcall octet-stream-renderer /dev/null))
    (bench1000000 (funcall string-renderer))
    (bench1000000 (funcall octets-renderer))
    (bench1000000 (with-fast-output (buff) (funcall fast-io-renderer buff)))))

(defun bench (tmpl)
  (bench/clta tmpl))

(loop :for tmpl :in *templates*
      :do (bench tmpl))<commit_msg>improve benchmark<commit_after>#|
  This file is a part of clta project.
  Copyright (c) 2014 κeen
|#

(in-package :cl-user)
(defpackage clta-bench
  (:use
   :cl
   :clta)
  (:import-from :fast-io
   :with-fast-output))
(in-package :clta-bench)

(defparameter *templates* '(("simple.tmpl" . ())))

(defmacro bench1000000 (title form)
  `(progn
     (write-line ,title)
     (time (loop :repeat 1000000 :do ,form))))

(defun bench/clta (tmpl args)
  (let ((stream-renderer (compile-template-file (make-backend :stream) tmpl ()))
        (octet-stream-renderer (compile-template-file (make-backend :octet-stream) tmpl ()))
        (string-renderer (compile-template-file (make-backend :string) tmpl ()))
        (octets-renderer (compile-template-file (make-backend :octets) tmpl ()))
        (fast-io-renderer (compile-template-file (make-backend :fast-io) tmpl ()))
        (/dev/null (make-broadcast-stream)))
    (bench1000000 (format nil "compiled stream backend with ~a" tmpl)
                  (apply stream-renderer /dev/null args))
    (bench1000000 (format nil "compiled octet stream backend with ~a" tmpl)
                  (apply octet-stream-renderer /dev/null args))
    (bench1000000 (format nil "compiled string backend with ~a" tmpl)
                  (apply string-renderer args))
    (bench1000000 (format nil "compiled octet backend with ~a" tmpl)
                  (apply octets-renderer args))
    (bench1000000 (format nil "compiled fast-io backend with ~a" tmpl)
                  (with-fast-output (buff) (apply fast-io-renderer buff args)))))

(defun bench (tmpl args)
  (bench/clta tmpl args))

(loop :for (tmpl . args) :in *templates*
      :do (bench tmpl args))
{'fraction_non_alphanumeric': 0.14905982905982906, 'fraction_numerical': 0.03623931623931624, 'mean_word_length': 3.341246290801187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4398804', 'n_tokens_mistral': 1071, 'n_tokens_neox': 985, 'n_words': 257}