benchmark, speed comparison: xah-html-mode vs mhtml-mode vs html-mode

By Xah Lee. Date: .
;; -*- coding: utf-8; lexical-binding: t; -*-
;; 2023-08-10

;; compare speeds of xah html mode vs several in emacs

;; result is inconclusive

(require 'benchmark)

(defun xf1 (Xfname Mode)
  "create temp buffer, insert file Xfname, make it major mode Mode"
  (let ((xbuf (generate-new-buffer "xtestspeed" t)))
    (set-buffer xbuf)
    (insert-file-contents Xfname nil nil nil t)
    (funcall (intern-soft Mode))
    ;; (kill-buffer xbuf)
    ))

(setq xi 1)
(setq xfile "~/web/xx1.html")

(benchmark-run xi (xf1 xfile 'xah-html-mode ))
;; (1.6 1 0.02)
;; (0.681044 0 0.0)
;; (0.1 1 0.02)

(benchmark-run xi (xf1 xfile 'html-mode ))
;; (1.5 1 0.02)
;; (0.69 1 0.02)
;; (0.11 1 0.02)

(benchmark-run xi (xf1 xfile 'mhtml-mode ))
;; (1.54 2 0.04)
;; (0.78 4 0.09)
;; (0.16 3 0.06)

;; HHHH---------------------------------------------------

(setq xi 100)

(defun xf3 (Xfname Mode)
  "create temp buffer, insert file Xfname, make it major mode Mode"
  (let ()
    (find-file-literally Xfname)
    (funcall (intern-soft Mode))
    (kill-buffer)))

(benchmark-run xi (xf3 "~/web/xx1.html" 'xah-html-mode ))
;; (0.61 1 0.)

(benchmark-run xi (xf3 "~/web/xx1.html" 'html-mode ))
;; (0.64 2 0.06)

(benchmark-run xi (xf3 "~/web/xx1.html" 'mhtml-mode ))
;; (0.75 4 0.15)

;; HHHH---------------------------------------------------

(setq xfiles (directory-files "c:/Users/xah/web/xahlee_info/talk_show/" t "html$" t))

(setq xi 1)

(defun xf2 (Mode)
  "create temp buffer, insert file Xfname, make it major mode Mode"
  (let ()
    (mapc
     (lambda (x)
       (find-file-literally x)
       (funcall (intern-soft Mode))
       (kill-buffer))
     xfiles)))

(benchmark-run xi (xf2 'xah-html-mode ))
;; (3.10 7 0.18)

(benchmark-run xi (xf2 'html-mode ))
;; (3.20 10 0.26)

(benchmark-run xi (xf2 'mhtml-mode ))
;; (3.48 19 0.48)