stat.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // =====================================================================================
  2. //
  3. // Filename: stat.cc
  4. //
  5. // Description: read one result
  6. //
  7. // Version: 1.0
  8. // Created: 2018年 03月 16日 星期五 22:02:12 CST
  9. // Revision: none
  10. // Compiler: g++
  11. //
  12. // Author: Jinkun Lin, jkunlin@gmail.com
  13. // Organization: School of EECS, Peking University
  14. //
  15. // =====================================================================================
  16. #include <cstdio>
  17. #include <fstream>
  18. #include <iostream>
  19. #include <sstream>
  20. #include <string>
  21. using namespace std;
  22. string basename(string name) {
  23. size_t begin = name.find_last_of('/');
  24. return name.substr(begin + 1, name.size() - begin);
  25. }
  26. int main(int argc, char const *argv[]) {
  27. if (argc != 2) {
  28. return 1;
  29. }
  30. string filename = argv[1];
  31. ifstream infile(filename);
  32. if (!infile) {
  33. std::cout << "file" << std::endl;
  34. return 1;
  35. }
  36. size_t b = filename.find_last_of('_') + 5;
  37. size_t e = filename.find_last_of('.');
  38. string seed = filename.substr(b, e - b);
  39. double cutoff = 100;
  40. string line, tmp;
  41. int size = 0, old_size = 0;
  42. double time = 0, old_time = 0;
  43. char exact = 'h', old_exact = 'h';
  44. /*
  45. // fastwclq
  46. while (getline(infile, line)) {
  47. istringstream is(line);
  48. for (int i = 0; i < 2; ++i) {
  49. is >> tmp;
  50. }
  51. is >> size >> time >> tmp >> exact;
  52. if (!is) {
  53. size = old_size;
  54. time = old_time;
  55. exact = old_exact;
  56. break;
  57. }
  58. if (time > cutoff) {
  59. size = old_size;
  60. time = old_time;
  61. exact = old_exact;
  62. break;
  63. } else {
  64. old_size = size;
  65. old_time = time;
  66. old_exact = exact;
  67. }
  68. }
  69. */
  70. // lscc
  71. while (getline(infile, line)) {
  72. istringstream is(line);
  73. for (int i = 0; i < 4; ++i) {
  74. is >> tmp;
  75. }
  76. char ch;
  77. is >> time >> ch >> size;
  78. if (!is) {
  79. size = old_size;
  80. time = old_time;
  81. exact = old_exact;
  82. break;
  83. }
  84. if (time > cutoff) {
  85. size = old_size;
  86. time = old_time;
  87. exact = old_exact;
  88. break;
  89. } else {
  90. old_size = size;
  91. old_time = time;
  92. old_exact = exact;
  93. }
  94. }
  95. // fanyi
  96. // getline(infile, line); // read time
  97. // while (getline(infile, line)) {
  98. // istringstream is(line);
  99. // for (int i = 0; i < 1; ++i) {
  100. // is >> tmp;
  101. // }
  102. // is >> size >> time;
  103. //
  104. // if (!is) {
  105. // size = old_size;
  106. // time = old_time;
  107. // exact = old_exact;
  108. // break;
  109. // }
  110. //
  111. // if (time > cutoff) {
  112. // size = old_size;
  113. // time = old_time;
  114. // exact = old_exact;
  115. // break;
  116. // } else {
  117. // old_size = size;
  118. // old_time = time;
  119. // old_exact = exact;
  120. // }
  121. // }
  122. std::cout << seed << '\t' << size << '\t' << time << '\t' << exact
  123. << std::endl;
  124. if (size == 0) {
  125. cerr << "size = 0\t" << basename(filename) << endl;
  126. }
  127. return 0;
  128. }