Skip to content

Instantly share code, notes, and snippets.

@darkleaf
Last active July 30, 2024 18:17
Show Gist options
  • Save darkleaf/c7a586edc202167a198af2d2e46149f6 to your computer and use it in GitHub Desktop.
Save darkleaf/c7a586edc202167a198af2d2e46149f6 to your computer and use it in GitHub Desktop.
(ns experiments.exceptions)
(comment
(require '[criterium.core :as c])
(c/quick-bench
(Object.))
;; Execution time mean : 5,429811 ns
(c/quick-bench
((fn [] (Object.))))
;; Execution time mean : 6,984797 ns
(c/quick-bench
((fn [] ["" {}])))
;; Execution time mean : 8,057194 ns
(let [ex (RuntimeException.)]
(c/quick-bench
(try
((fn [] (throw ex)))
(catch RuntimeException ex*
ex*))))
;; Execution time mean : 5,052186 ns
(c/quick-bench
(RuntimeException. ""))
;; Execution time mean : 3,264115 µs
;; ^^
;; -XX:-StackTraceInThrowable
;; Execution time mean : 61,303768 ns
(c/quick-bench
;; protected constructor
;; false - это отключить стектрейсы
(proxy [RuntimeException] ["" nil true false]))
;; Execution time mean : 25,065547 ns
;; прото проаверить
;; -XX:-StackTraceInThrowable
;; Execution time mean : 25,994738 ns
(c/quick-bench
(try
(throw (RuntimeException. ""))
(catch RuntimeException ex*
ex*)))
;; Execution time mean : 3,275888 µs
;; ^^
;; -XX:-StackTraceInThrowable
;; Execution time mean : 62,283648 ns
(c/quick-bench
(try
(throw (proxy [RuntimeException] ["" nil true false]))
(catch RuntimeException ex*
ex*)))
;; Execution time mean : 27,427171 ns
(require '[clojure.repl.deps :as deps])
(deps/add-libs '{darkleaf/no-stack-trace {:mvn/version "1.0.0"}})
(require '[darkleaf.no-stack-trace :as nst])
(c/quick-bench
(try
(throw (throw (nst/ex-info "" {})))
(catch RuntimeException ex*
ex*)))
;; Execution time mean : 17,792664 ns
(c/quick-bench
(assoc nil :foo :bar))
;; Execution time mean : 19,690760 ns
(c/quick-bench
(assoc {} :foo :bar))
;; Execution time mean : 23,187041 ns
#_"
* создать объект 8ns (5ns) -XX:-StackTraceInThrowable
* заранее созданное исключение 5ns
* stacktrace 3000ns 62ns
* no stacktrace 17ns (27ns)
* assoc 19ns
ребята недавно померяли на java
https://www.baeldung.com/java-exceptions-performance
stack no stack -XX:-StackTraceInThrowable
у меня 3000ns 17ns 62ns
у них 16.449ms 1.185ms
У меня разница на 2 порядка, а у инх на 1.
Они выключали стек по другой методе, через -XX:-StackTraceInThrowable
И программы бенчмарка разные.
"
,,,)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment