On 3/14/12 2:14 PM, Somchai Smythe wrote: > Hello, > > I am reporting a problem with performance, not correctness. > > While preparing some examples for a course lecture where I code the > same algorithm in many languages to compare languages, I ran some code > and while it was reasonably quick with ksh, it would just apparently > hang at 100% cpu in bash. I finally let it run overnight and it does > complete correctly in bash, but what takes ksh less than a minute > takes bash 6 1/2 hours to complete (and keeping one core at 100% the > entire 6.5 hours) on the same hardware. I suspect there may be some > special way to compile bash that I don't know about that maybe works > with arrays differently, so I reporting this.
I'd have to look at a profiling version of bash to confirm this, but my initial impression is that this is due to how arrays are implemented internally: ksh uses c-style arrays (which is why older versions limited sizes to 4096 elements), while bash uses sparse doubly-linked lists. The access time difference in big-O notation is obvious. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/