Guest User

Untitled

a guest
Jul 21st, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. $attempt = 30;
  4. #$target_time = get_time("59|16:27:28:017|INFO|CitiTickerBBOTradeHandler|ProcessNBBO|took:1290616048017425|");
  5. $target_time = get_time("52|16:54:05:595|INFO|3IN.L|EBBO|Symbol:3IN.L|Bid:0.0|BidSize:0|Ask:120.0|As");
  6. $target_time = $target_time-4000;
  7. print " Target: ".$target_time."ms\n";
  8.  
  9. my $min = 0;
  10. my ($max) = (stat("test_data"))[7];
  11.  
  12. open LOG, "<test_data" or die $!;
  13. my $seek = 1000000;
  14. seek(LOG, $seek, 0);
  15. $line = <LOG>;
  16. $line = <LOG>;
  17. my $found_time = get_time($line);
  18.  
  19. while($target_time-$found_time > 200000 || $target_time-$found_time < 0) {
  20. my $from_goal = $target_time-$found_time;
  21.  
  22. if($from_goal > 0) {
  23. print "-> left to goal\n";
  24. if($seek > $min) {
  25. $min = $seek;
  26. print "# Min seek: ".$min."\n";
  27. }
  28.  
  29. $bit = int(($max-$min)*.5);
  30. $seek = $min+$bit;
  31. print " ++ seek: ".$seek." [".$bit."]\n";
  32. } else {
  33. print "-> right to goal\n";
  34. if($seek < $max) {
  35. $max = $seek;
  36. print "# Max seek: ".$max."\n";
  37. }
  38.  
  39. $bit = int(($max-$min)*.5);
  40. $seek = $max-$bit;
  41. print " -- seek: ".$seek." [".$bit."]\n";
  42. }
  43.  
  44. if($attempt-- < 0) {
  45. print "> FUCK\n";
  46. seek(LOG, 0, 0);
  47. last;
  48. }
  49. seek(LOG, $seek, 0);
  50. $line = <LOG>;
  51. $line = <LOG>;
  52.  
  53. $found_time = get_time($line);
  54. print "Found Time: ".$found_time."ms\n";
  55. print " From Goal: ".($target_time-$found_time)."ms\n";
  56. print "################################################### ".$attempt."\n";
  57. }
  58. print "DONE\n";
  59.  
  60. close(LOG);
  61.  
  62.  
  63.  
  64. sub get_time {
  65. my $time = 0;
  66. if($_[0] =~ m/.*?\|(\d*?:\d*?:\d*?:\d*?)\|/) {
  67. @timesegs = split( /:/, $1);
  68. $time = ($timesegs[0]*60*60*1000)+($timesegs[1]*60*1000)+($timesegs[2]*1000)+($timesegs[3]);
  69. }
  70. $time;
  71. }
Add Comment
Please, Sign In to add comment