main_test.go 981 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package main
  2. import (
  3. "runtime"
  4. "testing"
  5. )
  6. var symbols = []string{
  7. "sc",
  8. "btc",
  9. "bty",
  10. "eth",
  11. "etc",
  12. "zec",
  13. "bts",
  14. "ltc",
  15. "bcc",
  16. "nycc",
  17. "wtc",
  18. }
  19. var periods = []string{
  20. "M1",
  21. "M5",
  22. "M15",
  23. "M30",
  24. "H1",
  25. "H2",
  26. "H4",
  27. "D1",
  28. "W1",
  29. "MN1",
  30. }
  31. func BenchmarkGetData(b *testing.B) {
  32. runtime.GOMAXPROCS(runtime.NumCPU())
  33. conf, err := readConf()
  34. if err != nil {
  35. b.Fatal("readConf", err)
  36. } else {
  37. *saddr1 = conf.Saddr1
  38. *saddr2 = conf.Saddr2
  39. *saddr3 = conf.Saddr3
  40. *saddr4 = conf.Saddr4
  41. }
  42. err = connectServer()
  43. if err != nil {
  44. b.Fatal("connect server", err)
  45. }
  46. resCh := make(chan int)
  47. for i := 0; i < b.N; i++ {
  48. go func() {
  49. for _, symbol := range symbols {
  50. for _, period := range periods {
  51. _, err := getData(symbol, period, "init", "100", "", "jQuery112406248373254640218_1472016715089", "0", "0", K_STYLE)
  52. if err != nil {
  53. b.Error(err)
  54. }
  55. }
  56. }
  57. resCh <- 1
  58. }()
  59. }
  60. for i := 0; i < b.N; i++ {
  61. <-resCh
  62. }
  63. }