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. //
  17. package logging
  18. import (
  19. "fmt"
  20. "os"
  21. "testing"
  22. )
  23. func BenchmarkSync(b *testing.B) {
  24. logger, _ := RichLogger("main")
  25. logger.SetLevel(NOTSET)
  26. for i := 0; i < b.N; i++ {
  27. logger.Error("this is a test from error")
  28. }
  29. logger.Flush()
  30. logger.Destroy()
  31. }
  32. func BenchmarkAsync(b *testing.B) {
  33. logger, _ := RichLogger("main")
  34. logger.SetLevel(NOTSET)
  35. for i := 0; i < b.N; i++ {
  36. logger.Error("this is a test from error")
  37. }
  38. logger.Flush()
  39. logger.Destroy()
  40. }
  41. func BenchmarkBasicSync(b *testing.B) {
  42. logger, _ := BasicLogger("main")
  43. logger.SetLevel(NOTSET)
  44. for i := 0; i < b.N; i++ {
  45. logger.Error("this is a test from error")
  46. }
  47. logger.Flush()
  48. logger.Destroy()
  49. }
  50. func BenchmarkBasicAsync(b *testing.B) {
  51. logger, _ := BasicLogger("main")
  52. logger.SetLevel(NOTSET)
  53. for i := 0; i < b.N; i++ {
  54. logger.Error("this is a test from error")
  55. }
  56. logger.Flush()
  57. logger.Destroy()
  58. }
  59. func BenchmarkPrintln(b *testing.B) {
  60. out, _ := os.Create("logging.log")
  61. for i := 0; i < b.N; i++ {
  62. fmt.Fprintln(out, "this is a test from error")
  63. }
  64. out.Close()
  65. }