Skip to content

Instantly share code, notes, and snippets.

@dmgerman
Last active May 21, 2024 22:24
Show Gist options
  • Save dmgerman/f862c1c78d2a870af1bf622add837fa4 to your computer and use it in GitHub Desktop.
Save dmgerman/f862c1c78d2a870af1bf622add837fa4 to your computer and use it in GitHub Desktop.
test a constructor that does not take named parameters

add a constructor that does not take named parameters

(cl-defstruct (org-roam-node (:constructor org-roam-node-create)
                             (:constructor org-roam-node-create-from-db
                                           (title
                                            id file file-title level todo
                                            pos priority scheduled deadline 
                                            properties olp atime  mtime tags
                                            aliases refs))
                             (:copier nil))
  "A heading or top level file with an assigned ID property."
  file file-title file-hash file-atime file-mtime
  id level point todo priority scheduled deadline title properties olp
  tags aliases refs)

test the original constructor 50,000 times

(defun dmg-test-create-node (row)
;; (org-roam-node-create &key FILE FILE-TITLE FILE-HASH FILE-ATIME FILE-MTIME
;;                            ID LEVEL POINT TODO PRIORITY
;;                            SCHEDULED DEADLINE TITLE PROPERTIES OLP
;;                           TAGS ALIASES REFS
;;                           DEADLINE TITLE PROPERTIES OLP TAGS ALIASES REFS)
       (pcase-let* ((`(,id ,file ,file-title ,level ,todo
                           ,pos ,priority
                           ,scheduled ,deadline ,title ,properties ,olp
                           ,atime ,mtime
                           ,tags ,aliases ,refs)
                     row)
                    )
         (org-roam-node-create 
                                         :file file
                                         :file-title file-title
                                         ;; file-hash
                                         :file-atime atime
                                         :file-mtime mtime
                                         
                                         :id id
                                         :level level
                                         :point pos
                                         :todo todo
                                         :priority priority
                                         
                                         :scheduled scheduled
                                         :deadline deadline
                                         :title title
                                         :properties properties
                                         :olp olp
                                         
                                         :tags tags
                                         :aliases aliases
                                         :refs refs))
       )
(defun dmg-test-function ()
  (dmg-test-create-node '("a" "b" "c" "d" "e" 
                          "f" "g" "h" "i" "j" 
                          "k" "l" "m" "n" "o"
                          (123 235 989) "q"; "r"
                         ; "s" "t"
                          )))
(defun dmg-test-function2()
  (dotimes (i 50000)
    (dmg-test-function)))


(cl-loop
 for i from 1 to 10
 collect (benchmark-run 1 (dmg-test-function2)))
8.29172300000000120.35438299999999856
8.27544620.3538370000000022
8.29961700000000120.35394900000000007
8.51577930.5367329999999981
8.32851620.36029200000000117
8.30781920.355912
8.46784530.5321849999999984
8.27331400000000120.3548100000000005
8.27520800000000120.3566400000000023
8.45251730.5341159999999974

test the new constructor (50,000 times)

(defun dmg-test-create-node (row)

;; (org-roam-node-create &key FILE FILE-TITLE FILE-HASH FILE-ATIME FILE-MTIME
;;                            ID LEVEL POINT TODO PRIORITY
;;                            SCHEDULED DEADLINE TITLE PROPERTIES OLP
;;                           TAGS ALIASES REFS
;;                           DEADLINE TITLE PROPERTIES OLP TAGS ALIASES REFS)
;;       (pcase-let* ((`(,id ,file ,file-title ,level ,todo
;;                           ,pos ,priority
;;                           ,scheduled ,deadline ,title ,properties ,olp
;;                           ,atime ,mtime
;;                           ,tags ,aliases ,refs)
;;                     row)
  (apply 'org-roam-node-create-from-db row)
                   
  )

(defun dmg-test-function ()
  (dmg-test-create-node '("a"  "b" "c" "d" "e" 
                          "f" "g" "h" "i" "j" 
                          "k" "l" "m" "n" "o"
                          (123 235 989) "q"  ; "r"
                         ; "s" "t"
                          )))
(defun dmg-test-function2()
  (dotimes (i 50000)
    (dmg-test-function)))


(cl-loop
 for i from 1 to 10
 collect (benchmark-run 1 (dmg-test-function2)))
0.634332999999999900.0
0.77489710.17708200000000218
0.5955400.0
0.59946800.0
0.77302710.17655199999999738
0.5962300.0
0.59829100.0
0.771629999999999910.17652800000000113
0.595812999999999900.0
0.77405310.17709299999999928
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment