<commit_before>;;; Copyright 2012-2020 Google LLC
;;;
;;; Use of this source code is governed by an MIT-style
;;; license that can be found in the LICENSE file or at
;;; https://opensource.org/licenses/MIT.

(defpackage #:cl-protobufs.test.timing
  (:use #:cl
        #:clunit
        #:cl-protobufs)
  (:local-nicknames
   (#:serial-proto #:cl-protobufs.serialization-test)
   (#:oneof-proto #:cl-protobufs.oneof-test)
   (#:proto3-proto #:cl-protobufs.proto3-test)
   (#:map-proto #:cl-protobufs.map-test)
   (#:pi #:cl-protobufs.implementation))
  (:export #:run))

(in-package #:cl-protobufs.test.timing)

(defsuite timing-suite (cl-protobufs.test:root-suite))

(defun run (&key use-debugger)
  "Run all tests in the test suite.
Parameters
  USE-DEBUGGER: On assert failure bring up the debugger."
  (clunit:run-suite 'timing-suite :use-debugger use-debugger
                                  :signal-condition-on-fail t))

(deftest basic-function-times (timing-suite)
  (print "Optional Field Test")
  (benchmark:with-timing (1000)
    (let ((optional-message (serial-proto:make-optional-message)))
      (serial-proto:optional-message.has-optional-no-default optional-message)
      (setf (serial-proto:optional-message.optional-no-default optional-message) 2)
      (serial-proto:optional-message.has-optional-no-default optional-message)
      (serial-proto:optional-message.clear-optional-no-default optional-message)))
  (print "Required Field Test")
  (benchmark:with-timing (1000)
    (let ((required-message (serial-proto:make-required-message)))
      (serial-proto:required-message.has-required-no-default required-message)
      (setf (serial-proto:required-message.required-no-default required-message) 2)
      (serial-proto:required-message.has-required-no-default required-message)
      (serial-proto:required-message.clear-required-no-default required-message)))
  (print "Onof Field Test")
  (benchmark:with-timing (1000)
    (let ((oneof-proto (oneof-proto:make-oneof-proto :intval 2)))
      (oneof-proto:oneof-proto.has-intval oneof-proto)
      (setf (oneof-proto:oneof-proto.intval oneof-proto) 2)
      (oneof-proto:oneof-proto.has-intval oneof-proto)
      (oneof-proto:oneof-proto.clear-intval oneof-proto)))
  (print "Map Field Test")
  (benchmark:with-timing (1000)
    (let ((map-proto (map-proto:make-map-all)))
      (map-proto:map-all.has-intmap map-proto)
      (setf (map-proto:map-all.intmap-gethash 1 map-proto) 1)
      (map-proto:map-all.has-intmap map-proto)
      (map-proto:map-all.clear-intmap map-proto)))
  (print "Singular Field Test")
  (benchmark:with-timing (1000)
    (let ((singular-proto (proto3-proto:make-all-singular)))
      (proto3-proto::all-singular.has-int32-value singular-proto)
      (setf (proto3-proto::all-singular.int32-value singular-proto) 1)
      (proto3-proto::all-singular.has-int32-value singular-proto)
      (proto3-proto:all-singular.clear-int32-value singular-proto)))
  (assert t))

(defvar *presidents*
  '("<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "Barack Obama")
  "A list of presidents from George Washington until Barack Obama")

(defun clear-serialization-functions (proto-name)
  #-sbcl
  (setf (get `,proto-name :serialize) nil
        (get `,proto-name :deserialize) nil)
  #+sbcl (fmakunbound (list :protobuf :serialize proto-name))
  #+sbcl (fmakunbound (list :protobuf :deserialize proto-name)))

(defun clear-proto3-serialization-functions ()
  (loop for message in '(proto3-proto:population
                         proto3-proto:address
                         proto3-proto:person)<commit_msg>Add <NAME> to our list of presidents in timing tests.<commit_after>;;; Copyright 2012-2020 Google LLC
;;;
;;; Use of this source code is governed by an MIT-style
;;; license that can be found in the LICENSE file or at
;;; https://opensource.org/licenses/MIT.

(defpackage #:cl-protobufs.test.timing
  (:use #:cl
        #:clunit
        #:cl-protobufs)
  (:local-nicknames
   (#:serial-proto #:cl-protobufs.serialization-test)
   (#:oneof-proto #:cl-protobufs.oneof-test)
   (#:proto3-proto #:cl-protobufs.proto3-test)
   (#:map-proto #:cl-protobufs.map-test)
   (#:pi #:cl-protobufs.implementation))
  (:export #:run))

(in-package #:cl-protobufs.test.timing)

(defsuite timing-suite (cl-protobufs.test:root-suite))

(defun run (&key use-debugger)
  "Run all tests in the test suite.
Parameters
  USE-DEBUGGER: On assert failure bring up the debugger."
  (clunit:run-suite 'timing-suite :use-debugger use-debugger
                                  :signal-condition-on-fail t))

(deftest basic-function-times (timing-suite)
  (print "Optional Field Test")
  (benchmark:with-timing (1000)
    (let ((optional-message (serial-proto:make-optional-message)))
      (serial-proto:optional-message.has-optional-no-default optional-message)
      (setf (serial-proto:optional-message.optional-no-default optional-message) 2)
      (serial-proto:optional-message.has-optional-no-default optional-message)
      (serial-proto:optional-message.clear-optional-no-default optional-message)))
  (print "Required Field Test")
  (benchmark:with-timing (1000)
    (let ((required-message (serial-proto:make-required-message)))
      (serial-proto:required-message.has-required-no-default required-message)
      (setf (serial-proto:required-message.required-no-default required-message) 2)
      (serial-proto:required-message.has-required-no-default required-message)
      (serial-proto:required-message.clear-required-no-default required-message)))
  (print "Onof Field Test")
  (benchmark:with-timing (1000)
    (let ((oneof-proto (oneof-proto:make-oneof-proto :intval 2)))
      (oneof-proto:oneof-proto.has-intval oneof-proto)
      (setf (oneof-proto:oneof-proto.intval oneof-proto) 2)
      (oneof-proto:oneof-proto.has-intval oneof-proto)
      (oneof-proto:oneof-proto.clear-intval oneof-proto)))
  (print "Map Field Test")
  (benchmark:with-timing (1000)
    (let ((map-proto (map-proto:make-map-all)))
      (map-proto:map-all.has-intmap map-proto)
      (setf (map-proto:map-all.intmap-gethash 1 map-proto) 1)
      (map-proto:map-all.has-intmap map-proto)
      (map-proto:map-all.clear-intmap map-proto)))
  (print "Singular Field Test")
  (benchmark:with-timing (1000)
    (let ((singular-proto (proto3-proto:make-all-singular)))
      (proto3-proto::all-singular.has-int32-value singular-proto)
      (setf (proto3-proto::all-singular.int32-value singular-proto) 1)
      (proto3-proto::all-singular.has-int32-value singular-proto)
      (proto3-proto:all-singular.clear-int32-value singular-proto)))
  (assert t))

(defvar *presidents*
  '("<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>"
    "<NAME>" "<NAME>" "<NAME>" "<NAME>")
  "A list of presidents from George Washington until now.")

(defun clear-serialization-functions (proto-name)
  #-sbcl
  (setf (get `,proto-name :serialize) nil
        (get `,proto-name :deserialize) nil)
  #+sbcl (fmakunbound (list :protobuf :serialize proto-name))
  #+sbcl (fmakunbound (list :protobuf :deserialize proto-name)))

(defun clear-proto3-serialization-functions ()
  (loop for message in '(proto3-proto:population
                         proto3-proto:address
                         proto3-proto:person)
{'fraction_non_alphanumeric': 0.1753861484803189, 'fraction_numerical': 0.013452914798206279, 'mean_word_length': 3.646412037037037, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 93, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2938055', 'n_tokens_mistral': 2793, 'n_tokens_neox': 2720, 'n_words': 550}