last day (15 days later) » 

04:01
Thank you.
It works if I run dpkg-reconfigure dash, and set /bin/sh to bash.
But not if I run bash --posix.
I think the bash --posix thing won't work unless you do --noediting as well.
The _bench() was just something I wrote in like 3 minutes for your answer.
It's probably not comprehensive in all its checks... That's for sure.
It's better though to use sh because that's basically: bash --norc --noprofile --posix.
I think.
readline screws it up.
No, it doesn't work with any of these options, but there's no problem, since I got it to work by setting bash as the default shell.
It's good to mention that in the answer, so people can do their own tests :)
I think I will - but are you sure? It won't if you call sh_bench() with those - because they'll get evaluated out.
But if I change the last line of sh_nlseq() to read:
bash --noediting --norc --noprofile --posix -si -- "$1" "$2" "$3" >/dev/null
I tried ne='--norc --noprofile --posix --noediting'
04:11
Yeah - that won't work. It is split too late.
When I change it in shell invocation, it works.
Still, maybe I'll fix that.
And in ksh, it won't stop counting!
04:37
Yeah, I don't know what it's doing in ksh - because I don't have it. You should try to figure out how to kill the shell from the prompt. IT will keep going forever unless the prompt kills the shell.
Anyway, I fixed the other thing. I'm making the edit now.
OK, that's great!
@TeresaeJunior - see, I changed the way the arguments are passed, and I used export to declare variables in a loop. That's fine because it's all contained in the initial sh_bench() ( subshell ) anyway - so it doesn't affect the current shell environment - and the sh_nlseq() thing invokes its subshell with env -.
I'm not certain how to make it work with zsh, though. I need to do something like emulate sh - but it's not a simple thing to hand in as yet, I don't think.
04:52
I'm sorry, @mikeserv, but I can't fix it myself because the code is a bit complicated, but the new code doesn't work anymore:
(teresaejunior)> sh_nlseq() {
> tr \\0 \\n </dev/zero | env - ENV= \
> PS1='${z:+$(kill -PIPE $$)}${z0+${3:-
> }}$((((n=n+(i=${2:-1}))-i)+${z0=0}))\
> ${0%%*[s${z:=${z0#$((n>${1-100}))}}]*}' \
> $sh "$@" -si -- "$end" "$int" "$sep" >/dev/null
> } 2>&1

(teresaejunior)> sh_bench() (
>     sh=$(command -v "$1") ; shift
>     for opt in end int sep
>     do  export "$opt=$1"
>     ${1+shift} ; done
>     case    "$(readlink -e "$sh")"                        in
>     (*bash) set -- --noediting --noprofile --norc --posix ;;
0 can't open... Hmmm...
Just a sec. Sorry about this.
@TeresaeJunior - I think it's the quotes.
No - I updated everything but a very important line - the actual call to sh_nlseq was still "$1" not "$@"
@TeresaeJunior - now?
After changing the way the arguments should be passed I didn't change the way I passed them because I forgot to edit this line:
time ( sh_nlseq >&${null:-1} "$1" )
Which now reads:
time ( sh_nlseq "$@" >&${null:-1} )
It works well now, thank you!
Yeah, sorry. It was a bonehead mistake.
I'll try to figure out what to do about zsh - cause I'd like to see how it performs.
05:17
My tests resulted the same as yours. I also included pdksh, which is faster than mksh, but still three times slower than dash.
Well, pdksh is faster than mksh, but the package description says "transitional dummy package to migrate from pdksh to mksh", lol
Where can I get pdksh? Or ksh?
They were just packages for you?
@TeresaeJunior Yes, dash is very fast. I try to write everything I'll ever use twice with POSIX portable and dash friendly syntax.
05:32
I'm on Debian, there are packages for ksh and pdksh. Although, as I said, the package description for pdksh states it is just a transitional package for mksh.
I did some reasearch, and readlink /bin/pdksh outputs lksh.
man lksh says "lksh is a command interpreter intended exclusive for running legacy shell scripts."
pdksh seems more like an outdated shell.
ksh, on the other hand, comes from kornshell.com
Hmm... I thought that was not a free thing...
nevermind - apparently AT&T open-sourced it.
For the last 14 years! OMG, for how long have you been coding?
05:52
While searching in my old notes, I found that I gave up on dash a few years ago after discovering I could not redirect output to files whose names contained an uppercase accent (like >ÁÀÂÃÉÊÍÓÔÕÚÜÇÑ), but it seems to have been fixed now.
Yeah - I would have imagined that kind of thing could be handled fairly easily with links. One thing I do in order to not have to worry about weird characters in filenames looks kind of like this:
set -- * ; ls -1qdi "$@" | while read inum na ; do ln "$1" ../links/"$inum" ; shift ; done
@TeresaeJunior I dunno if that works as written - it's close though.
06:08
I'll keep this code for when I need it, thanks!
This small code works in all shells, but I think it lacks many kind of tests (just run `time bash filename')
x=1
while :; do
	for i in 1 2 3; do
		case $i in
			a)
			;;
			b)
			;;
			c)
			;;
			1)
				if false; then
					:
				elif true; then
					:
				else
					:
				fi
			;;
			*)
				continue
			;;
		esac
	done

	if [ $x = 50000 ]; then
		break
	else
		x=$((x+1))
	fi
done
So this is kinda what I did with my prompt thing, yeah? Same idea anyway?
What's this do:
if false; then
:
elif true; then
:
else
:
fi
It does nothing, just like the rest of the script :P
Oh. Gotcha.
It works - right?
I just wrote it, it's more like a code golf. But I don't know if it tests properly reading input, arithmetic evaluation, and variable expansion.
OK, arithmetic evaluation it does
The rest it doesn't.
variable expansion can be done with just a ${foo:-}, right
reading input doesn't really fit in this code.
07:02
@TeresaeJunior - I dunno if those things constitute a full test. As I stated there, it is pretty arbitrary. But basically my prompt thing reads one line of input per increment - so 500000 might equate to 500000 commands, you know?
@TeresaeJunior yes - you can unset var ; [ "${var-?}" = ? ] || exit or something.
08:01
@mikeserv I did many tests with your code and mine, and the result is basically:
The fastest: dash and busybox ash
I didn't think to try that one. Mine works with busybox?
No, it doesn't, but it is a different set of tests, so it gives me a clue on those that work
The slowest: zsh and bash, bash being still much slower than zsh
In both my script and yours dash is the fastest, bash the slowest
I have edited mine recently - it's much simplified.
And it will take experimental options too.
Great, I'll have a look
So you can sh_bench 'shell --option --option' repeats
I still don't know if it will work with busybox... Though I might as well find out.
08:21
@TeresaeJunior - almost works with busybox... I'll have that together in a sec, I think...
OK!
You have posted
sh_bench() (
instead of
sh_bench() {
( -> {
Yeah.
It's been that way the whole time.
@TeresaeJunior - that's a simple means of declaring a function that occurs within a subshell. It's POSIX.
But the bottom thing is broken.
Oops - I had the end of it like a } but it should have been a ).
Anyway, I also posted the changes needed to make it work with busybox.
I never knew that! It is interesting!
Yeah, it would not work, because of the }
Well, that was a mistake - sorry. It does now.
@TeresaeJunior - dash still stomps busybox in my test - twice as fast.
08:41
Yes, dash is faster, unless you use busybox utilities, rather than GNU utilities.
But I don't use any utilities - they're all shell builtins.
No, not you, but I did some other tests.
ksh seems faster than mksh and even faster than busybox in some of my tests, but nothing can beat dash.
Well, what I said is not totally true either.
I use tr and env - but each is invoked only once at the same time the shell is. From there on the shell just increments on its input.
09:23
@TeresaeJunior - I did get ksh93 - almost got it wrangled...
09:48
It will be nice to test your code with ksh, because it has many more features than mksh, and some neat features not found in bash. It is definitely faster than bash, and somewhat faster than mksh.
The results for this code:
x=1
while :; do
  for i in 1 2 3; do
    case $i in
      1)
        if  false; then
          :
        elif true; then
          :
        fi
      ;;
      *)
        ${foo:-} &&
          continue
      ;;
    esac
  done

  printf "a\nb\nc" | while read line; do
    eval $line=$line
  done

  if [ $x = 5000 ]; then
    break
  else
    x=$((x+1))
  fi
done
busybox sh

real 0m1.529s
user 0m0.376s
sys 0m0.642s

dash

real 0m1.643s
user 0m0.159s
sys 0m0.911s

zsh

real 0m2.062s
user 0m0.665s
sys 0m0.942s

ksh

real 0m2.272s
user 0m0.796s
sys 0m0.873s

mksh

real 0m2.357s
user 0m0.469s
sys 0m0.918s

yash

real 0m2.452s
user 0m0.368s
sys 0m0.951s

bash

real 0m3.725s
user 0m0.643s
sys 0m1.060s
zsh here is fast
:
bash-static
real 0m2.976s
user 0m0.713s
sys 0m0.826s
bash-static here is bash 4.3.11 instead of 4.2.
@TeresaeJunior - it works right now. It just inserts an extra line - which is no problem for the benchmarking, but it doesn't behave as I'd expect for the old failed experiment.
Oh well.
10:12
@TeresaeJunior - I've made an edit - it will work with ksh.

  last day (15 days later) »