Advertisement
teknoraver

cat2

Nov 29th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.32 KB | None | 0 0
  1. $ time cat linux-4.14.2.tar >new
  2.  
  3. real    0m0,296s
  4. user    0m0,004s
  5. sys     0m0,291s
  6. $ time cat linux-4.14.2.tar >new
  7.  
  8. real    0m0,297s
  9. user    0m0,004s
  10. sys     0m0,293s
  11. $ time cat linux-4.14.2.tar >new
  12.  
  13. real    0m0,306s
  14. user    0m0,000s
  15. sys     0m0,306s
  16. $ time cat linux-4.14.2.tar >new
  17.  
  18. real    0m0,293s
  19. user    0m0,000s
  20. sys     0m0,292s
  21. $ time cat linux-4.14.2.tar >new
  22.  
  23. real    0m0,299s
  24. user    0m0,000s
  25. sys     0m0,299s
  26. $ time cat linux-4.14.2.tar >new
  27.  
  28. real    0m0,296s
  29. user    0m0,000s
  30. sys     0m0,295s
  31. $ time cat2 linux-4.14.2.tar >new
  32.  
  33. real    0m0,265s
  34. user    0m0,000s
  35. sys     0m0,265s
  36. $ time cat2 linux-4.14.2.tar >new
  37.  
  38. real    0m0,266s
  39. user    0m0,000s
  40. sys     0m0,265s
  41. $ time cat2 linux-4.14.2.tar >new
  42.  
  43. real    0m0,273s
  44. user    0m0,000s
  45. sys     0m0,274s
  46. $ time cat2 linux-4.14.2.tar >new
  47.  
  48. real    0m0,265s
  49. user    0m0,000s
  50. sys     0m0,265s
  51. $ time cat2 linux-4.14.2.tar >new
  52.  
  53. real    0m0,265s
  54. user    0m0,000s
  55. sys     0m0,265s
  56. $ time cat2 linux-4.14.2.tar >new
  57.  
  58. real    0m0,268s
  59. user    0m0,000s
  60. sys     0m0,268s
  61.  
  62. $ strace cat linux-4.14.2.tar 2>&1 >new |wc -l
  63. 12630
  64.  
  65. $ strace cat2 linux-4.14.2.tar 2>&1 >new |wc -l
  66. 42
  67.  
  68. diff --git a/src/cat.c b/src/cat.c
  69. index a3680a3fc..06cf7a2bc 100644
  70. --- a/src/cat.c
  71. +++ b/src/cat.c
  72. @@ -32,6 +32,10 @@
  73.  #endif
  74.  #include <sys/ioctl.h>
  75.  
  76. +#ifdef __linux__
  77. +# include <sys/sendfile.h>
  78. +#endif
  79. +
  80.  #include "system.h"
  81.  #include "ioblksize.h"
  82.  #include "die.h"
  83. @@ -157,13 +161,21 @@ simple_cat (
  84.          call.  */
  85.       size_t bufsize)
  86.  {
  87. -  /* Actual number of characters read, and therefore written.  */
  88. -  size_t n_read;
  89. -
  90.    /* Loop until the end of the file.  */
  91.  
  92.    while (true)
  93.      {
  94. +#ifdef __linux__
  95. +      /* maximum size transferred by sendfile() as in manpage */
  96. +      ssize_t xfer = sendfile(STDOUT_FILENO, input_desc, NULL, 0x7ffff000);
  97. +      if (xfer == -1)
  98. +        return false;
  99. +      if (xfer < 0x7ffff000)
  100. +        return true;
  101. +#else
  102. +      /* Actual number of characters read, and therefore written.  */
  103. +      size_t n_read;
  104. +
  105.        /* Read a block of input.  */
  106.  
  107.        n_read = safe_read (input_desc, buf, bufsize);
  108. @@ -186,6 +198,7 @@ simple_cat (
  109.          if (full_write (STDOUT_FILENO, buf, n) != n)
  110.            die (EXIT_FAILURE, errno, _("write error"));
  111.        }
  112. +#endif
  113.      }
  114.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement