bat icon indicating copy to clipboard operation
bat copied to clipboard

30x slower than cat when redirecting?

Open cgbur opened this issue 3 years ago • 1 comments

I have a log file, plaintext, that is 5.7 GiB. I had replaced my cat with bat and noticed I was getting very slow performance chopping files with cat | head -c. Here are some measurements after I undid bat as my default.

cat vs bat

❯ time cat log > /dev/null

________________________________________________________
Executed in  806.86 millis    fish           external
   usr time   28.21 millis  258.00 micros   27.95 millis
   sys time  778.76 millis   68.00 micros  778.70 millis
❯ time bat log > /dev/null

________________________________________________________
Executed in   29.04 secs    fish           external
   usr time   12.39 secs  400.00 micros   12.39 secs
   sys time   16.65 secs    0.00 micros   16.65 secs
❯ time bat log --plain > /dev/null

________________________________________________________
Executed in   29.45 secs    fish           external
   usr time   12.61 secs  293.00 micros   12.61 secs
   sys time   16.84 secs   81.00 micros   16.84 secs

How did you install bat?

cargo install --locked bat --force

❯ bat -V
bat 0.21.0
rustc 1.62.0 (a8314ef7d 2022-06-27)

bat version and environment

❯ bat log --diagnostic

Software version

bat 0.21.0

Operating system

Linux 5.4.196-119.356.amzn2int.x86_64

Command-line

bat log --diagnostic

Environment variables

SHELL=/bin/zsh
PAGER=<not set>
LESS=<not set>
LANG=en_US.UTF-8
LC_ALL=<not set>
BAT_PAGER=<not set>
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
XDG_CONFIG_HOME=<not set>
XDG_CACHE_HOME=<not set>
COLORTERM=<not set>
NO_COLOR=<not set>
MANPAGER=<not set>

Config file

Could not read contents of '....config/bat/config': No such file or directory (os error 2).

Custom assets metadata

Could not read contents of '/...cache/bat/metadata.yaml': No such file or directory (os error 2).

Custom assets

`.....cache/bat' not found

Compile time information

  • Profile: release
  • Target triple: x86_64-unknown-linux-gnu
  • Family: unix
  • OS: linux
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: fxsr,sse,sse2
  • Host: x86_64-unknown-linux-gnu

Less version

> less --version
less 458 (POSIX regular expressions)
Copyright (C) 1984-2012 Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less

cgbur avatar Jul 14 '22 18:07 cgbur

Thank you for reporting and for the nice benchmarks! This is actually a known problem, most notably analyzed in https://github.com/sharkdp/bat/issues/304#issuecomment-420416969. Quoting from that comment:

So even with bats loop-through mode, it is two orders of magnitude slower than cat.

Even though that analyzis is now 4 years old it seems as if it is still approximately true, based on your benchmarks.

Enselic avatar Jul 14 '22 19:07 Enselic

closing in favor of #304

sharkdp avatar Sep 06 '22 21:09 sharkdp