performance.rb 895 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env ruby
  2. #--
  3. # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
  4. # Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
  5. # All rights reserved.
  6. # Permission is granted for use, copying, modification, distribution,
  7. # and distribution of modified versions of this work as long as the
  8. # above copyright notice is included.
  9. #++
  10. require 'builder/xmlmarkup'
  11. require 'benchmark'
  12. text = "This is a test of the new xml markup. Iñtërnâtiônàlizætiøn\n" * 10000
  13. include Benchmark # we need the CAPTION and FMTSTR constants
  14. include Builder
  15. n = 50
  16. Benchmark.benchmark do |bm|
  17. tf = bm.report("base") {
  18. n.times do
  19. x = XmlMarkup.new
  20. x.text(text)
  21. x.target!
  22. end
  23. }
  24. def XmlMarkup._escape(text)
  25. text.to_xs
  26. end
  27. tf = bm.report("to_xs") {
  28. n.times do
  29. x = XmlMarkup.new
  30. x.text(text)
  31. x.target!
  32. end
  33. }
  34. end