hash.bm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ;;; hash.bm --- Hash functions. -*- Scheme -*-
  2. ;;;
  3. ;;; Copyright (C) 2015 Free Software Foundation, Inc.
  4. ;;;
  5. ;;; This program is free software; you can redistribute it and/or
  6. ;;; modify it under the terms of the GNU Lesser General Public License
  7. ;;; as published by the Free Software Foundation; either version 3, or
  8. ;;; (at your option) any later version.
  9. ;;;
  10. ;;; This program is distributed in the hope that it will be useful,
  11. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;;; GNU Lesser General Public License for more details.
  14. ;;;
  15. ;;; You should have received a copy of the GNU Lesser General Public
  16. ;;; License along with this software; see the file COPYING.LESSER. If
  17. ;;; not, write to the Free Software Foundation, Inc., 51 Franklin
  18. ;;; Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. (define-module (benchmarks write)
  20. #:use-module (benchmark-suite lib))
  21. (define %narrow-string
  22. (make-string 30 #\a))
  23. (define %wide-string
  24. (make-string 30 #\λ))
  25. (define %long-string
  26. (make-string 300 #\x))
  27. (define-syntax repeat
  28. (lambda (s)
  29. (syntax-case s ()
  30. ((_ 1 exp)
  31. #'exp)
  32. ((_ count exp)
  33. (with-syntax ((count (- (syntax->datum #'count) 1)))
  34. #'(begin
  35. exp
  36. (repeat count exp)))))))
  37. (with-benchmark-prefix "string-hash"
  38. (benchmark "narrow string" 100000
  39. (repeat 100 (string-hash %narrow-string)))
  40. (benchmark "wide string" 100000
  41. (repeat 100 (string-hash %wide-string)))
  42. (benchmark "long string" 100000
  43. (repeat 100 (string-hash %long-string))))