Plaster
New
List
Login
common-lisp
default
anonymous
2020.10.16 09:44:40
(in-package :cl-user) (defclass scanner () ()) (defmethod whitespacep ((scanner scanner) (char character)) (loop :for c :across #(#\Space #\Page #\Tab #\Return #\Newline) :thereis (char= char c))) (defmethod make-whitespace-predicate ((scanner scanner)) (lambda (char) (loop :for c :across #(#\Space #\Page #\Tab #\Return #\Newline) :thereis (char= char c)))) (defun test-1 () (loop :with scanner = (make-instance 'scanner) :with char = #\Space :for i :from 0 :to 100000000 :do (whitespacep scanner char))) (defun test-2 () (loop :with scanner = (make-instance 'scanner) :with pred = (make-whitespace-predicate scanner) :with char = #\Space :for i :from 0 :to 100000000 :do (funcall pred char))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CL-USER> (time (test-1)) Evaluation took: 1.528 seconds of real time 1.528682 seconds of total run time (1.528605 user, 0.000077 system) 100.07% CPU 6 lambdas converted 5,033,598,591 processor cycles 229,200 bytes consed CL-USER> (time (test-2)) Evaluation took: 0.596 seconds of real time 0.595393 seconds of total run time (0.595372 user, 0.000021 system) 99.83% CPU 1,960,685,614 processor cycles 0 bytes consed
Raw
Annotate
Repaste
Edit