logging_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2013, Cong Ding. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // author: Cong Ding <dinggnu@gmail.com>
  16. package logging
  17. import (
  18. "fmt"
  19. "os"
  20. "testing"
  21. )
  22. func BenchmarkSync(b *testing.B) {
  23. logger, _ := RichLogger("main")
  24. logger.SetLevel(NOTSET)
  25. for i := 0; i < b.N; i++ {
  26. logger.Error("this is a test from error")
  27. }
  28. logger.Flush()
  29. logger.Destroy()
  30. }
  31. func BenchmarkAsync(b *testing.B) {
  32. logger, _ := RichLogger("main")
  33. logger.SetLevel(NOTSET)
  34. for i := 0; i < b.N; i++ {
  35. logger.Error("this is a test from error")
  36. }
  37. logger.Flush()
  38. logger.Destroy()
  39. }
  40. func BenchmarkBasicSync(b *testing.B) {
  41. logger, _ := BasicLogger("main")
  42. logger.SetLevel(NOTSET)
  43. for i := 0; i < b.N; i++ {
  44. logger.Error("this is a test from error")
  45. }
  46. logger.Flush()
  47. logger.Destroy()
  48. }
  49. func BenchmarkBasicAsync(b *testing.B) {
  50. logger, _ := BasicLogger("main")
  51. logger.SetLevel(NOTSET)
  52. for i := 0; i < b.N; i++ {
  53. logger.Error("this is a test from error")
  54. }
  55. logger.Flush()
  56. logger.Destroy()
  57. }
  58. func BenchmarkPrintln(b *testing.B) {
  59. out, _ := os.Create("logging.log")
  60. for i := 0; i < b.N; i++ {
  61. fmt.Fprintln(out, "this is a test from error")
  62. }
  63. out.Close()
  64. }