The math builtin in fish is extremely slow (~30x slower than bash arithmetic).
Reproduction Steps:
-
Run the math builtin for simple arithmetic (tested on fish 2.3.0):
$ time -p fish -c 'for i in (seq 100); math "$i * 100000" > /dev/null; end'
-
Test bash's builtin arithmetic:
$ time -p bash -c 'for i in $(seq 100); do echo $(( $i * 100000 )) > /dev/null; done'
Expected behavior:
The execution time of the math builtin should be on the same order of magnitude as bash arithmetic.
Observed behavior:
The math builtin is ~30x slower than bash arithmetic for the simple test case above, as measured on a Raspberry Pi B+:
$ time -p fish -c 'for i in (seq 100); math "$i * 100000" > /dev/null; end'
real 5.25
user 1.98
sys 1.49
$ time -p bash -c 'for i in $(seq 100); do echo $(( $i * 100000 )) > /dev/null; done'
real 0.16
user 0.06
sys 0.00
Additional information:
I ran into this problem when developing the fish-command-timer script, which makes multiple consecutive calls to math to breakdown a timestamp difference into hours, minutes and seconds. On slower hardware such as the Raspberry Pi, the multiple math invocations take ~1s to execute, which renders the experience painful. There aren't any alternatives to the math builtin without additional dependencies.
Fish version: 2.3.0
Operating system: Arch Linux ARM for Raspberry Pi
Terminal or terminal emulator: MATE Terminal 1.12.1
The
mathbuiltin in fish is extremely slow (~30x slower than bash arithmetic).Reproduction Steps:
Run the
mathbuiltin for simple arithmetic (tested on fish 2.3.0):Test bash's builtin arithmetic:
Expected behavior:
The execution time of the
mathbuiltin should be on the same order of magnitude as bash arithmetic.Observed behavior:
The
mathbuiltin is ~30x slower than bash arithmetic for the simple test case above, as measured on a Raspberry Pi B+:Additional information:
I ran into this problem when developing the fish-command-timer script, which makes multiple consecutive calls to
mathto breakdown a timestamp difference into hours, minutes and seconds. On slower hardware such as the Raspberry Pi, the multiplemathinvocations take ~1s to execute, which renders the experience painful. There aren't any alternatives to themathbuiltin without additional dependencies.Fish version: 2.3.0
Operating system: Arch Linux ARM for Raspberry Pi
Terminal or terminal emulator: MATE Terminal 1.12.1