Slow printing speed

Post Reply
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Slow printing speed

Post by Robert »

I recently ran an algorithm which reported the results below to the Log window. It took a full minute.

When I simply replaced the blobs, unicode 25CF, with '×', ASCII D8, it took less than 15 seconds.

Is this slowness with unicode characters necessary?

(If you really want to know, its a table of the Jacobi symbol (m/p).)

Code: Select all

                            3   5   7  11  13  17  19  23  29  31  37  41
  1     264746434995953     ·   ·   ●   ●   ●   ·   ●   ·   ●   ●   ●   ●    8   0.481   Record
  2     529492869991906     ●   ●   ●   ·   ·   ·   ·   ·   ·   ●   ·   ●    5   0.733   Record
  3     794239304987859     ●   ●   ·   ●   ●   ●   ·   ·   ·   ·   ●   ·    6   0.787   Record
  4    1058985739983812     ·   ·   ●   ●   ●   ·   ●   ·   ●   ●   ●   ●    8   0.481
  5    1323732174979765     ●   ●   ·   ●   ·   ●   ●   ●   ●   ●   ·   ●    9   0.87    Record
  6    1588478609975718     ●   ·   ·   ·   ·   ●   ●   ·   ●   ·   ·   ·    4   0.479
  7    1853225044971671     ·   ●   ●   ·   ·   ●   ●   ●   ●   ●   ●   ·    8   0.592
  8    2117971479967624     ●   ●   ●   ·   ·   ·   ·   ·   ·   ●   ·   ●    5   0.733
  9    2382717914963577     ●   ·   ●   ●   ●   ·   ●   ·   ●   ●   ●   ●    9   0.815
 10    2647464349959530     ·   ●   ·   ·   ●   ●   ·   ●   ·   ●   ●   ●    7   0.463
 11    2912210784955483     ●   ·   ●   ●   ·   ●   ●   ●   ·   ·   ●   ·    7   0.749
 12    3176957219951436     ●   ●   ·   ●   ●   ●   ·   ·   ·   ·   ●   ·    6   0.787
 13    3441703654947389     ·   ●   ·   ·   ●   ·   ·   ·   ●   ·   ·   ·    3   0.311
 14    3706450089943342     ●   ·   ●   ●   ●   ●   ·   ●   ·   ●   ·   ·    7   0.779
 15    3971196524939295     ●   ●   ●   ●   ·   ·   ·   ●   ·   ·   ·   ·    5   0.811
 16    4235942959935248     ·   ·   ●   ●   ●   ·   ●   ·   ●   ●   ●   ●    8   0.481
 17    4500689394931201     ●   ●   ·   ·   ●   ●   ●   ●   ·   ·   ·   ·    6   0.765
 18    4765435829927154     ●   ●   ●   ·   ·   ·   ·   ·   ·   ●   ·   ●    5   0.733
 19    5030182264923107     ·   ·   ·   ·   ·   ·   ●   ●   ·   ●   ·   ·    3   0.128
 20    5294928699919060     ●   ●   ·   ●   ·   ●   ●   ●   ●   ●   ·   ●    9   0.87 
 21    5559675134915013     ●   ·   ●   ·   ·   ·   ·   ●   ·   ·   ●   ●    5   0.571
 22    5824421569910966     ·   ●   ●   ●   ●   ●   ·   ●   ●   ·   ·   ·    7   0.647
 23    6089168004906919     ●   ●   ●   ●   ●   ●   ●   ●   ●   ·   ·   ●   10   1.058   Record
 24    6353914439902872     ●   ·   ·   ·   ·   ●   ●   ·   ●   ·   ·   ·    4   0.479
 25    6618660874898825     ·   ●   ●   ●   ●   ·   ●   ·   ●   ●   ●   ●    9   0.681
 26    6883407309894778     ●   ·   ·   ●   ●   ·   ●   ·   ·   ·   ●   ·    5   0.581
 27    7148153744890731     ●   ●   ·   ●   ●   ●   ·   ·   ·   ·   ●   ·    6   0.787
 28    7412900179886684     ·   ●   ●   ·   ·   ●   ●   ●   ●   ●   ●   ·    8   0.592
 29    7677646614882637     ●   ·   ●   ·   ●   ●   ·   ·   ●   ·   ·   ·    5   0.646
 30    7942393049878590     ●   ●   ●   ·   ●   ·   ●   ●   ●   ·   ●   ·    8   0.911
 31    8207139484874543     ·   ·   ·   ●   ·   ●   ·   ·   ·   ●   ·   ●    4   0.206
 32    8471885919870496     ●   ●   ●   ·   ·   ·   ·   ·   ·   ●   ·   ●    5   0.733
 33    8736632354866449     ●   ●   ·   ●   ·   ·   ·   ●   ●   ●   ●   ●    8   0.786
 34    9001378789862402     ·   ·   ·   ●   ·   ●   ·   ●   ●   ·   ●   ·    5   0.255
 35    9266125224858355     ●   ●   ●   ·   ●   ·   ●   ·   ●   ●   ·   ·    7   0.872
 36    9530871659854308     ●   ·   ●   ●   ●   ·   ●   ·   ●   ●   ●   ●    9   0.815
 37    9795618094850261     ·   ●   ●   ●   ·   ●   ·   ●   ·   ·   ●   ●    7   0.587
 38   10060364529846214     ●   ●   ·   ●   ●   ·   ●   ●   ●   ●   ●   ·    9   0.891
 39   10325110964842167     ●   ·   ●   ·   ●   ●   ●   ·   ·   ●   ·   ●    7   0.721
 40   10589857399838120     ·   ●   ·   ·   ●   ●   ·   ●   ·   ●   ●   ●    7   0.463
 41   10854603834834073     ●   ·   ·   ·   ·   ●   ·   ·   ·   ●   ●   ●    5   0.476
 42   11119350269830026     ●   ●   ●   ●   ●   ·   ●   ●   ●   ·   ·   ●    9   0.999
 43   11384096704825979     ·   ●   ●   ·   ●   ·   ●   ●   ·   ·   ·   ●    6   0.54 
 44   11648843139821932     ●   ·   ●   ●   ·   ●   ●   ●   ·   ·   ●   ·    7   0.749
 45   11913589574817885     ●   ●   ·   ●   ·   ●   ●   ●   ●   ●   ·   ●    9   0.87 
 46   12178336009813838     ·   ·   ●   ·   ·   ●   ·   ●   ·   ·   ●   ●    5   0.297
 47   12443082444809791     ●   ●   ·   ●   ·   ·   ●   ·   ·   ●   ●   ·    6   0.736
 48   12707828879805744     ●   ●   ·   ●   ●   ●   ·   ·   ·   ·   ●   ·    6   0.787
 49   12972575314801697     ·   ·   ●   ●   ●   ·   ●   ·   ●   ●   ●   ●    8   0.481
 50   13237321749797650     ●   ●   ●   ·   ·   ·   ·   ·   ·   ●   ·   ●    5   0.733
 51   13502068184793603     ●   ·   ●   ·   ●   ●   ·   ●   ●   ●   ·   ●    8   0.747
 52   13766814619789556     ·   ●   ·   ·   ●   ·   ·   ·   ●   ·   ·   ·    3   0.311
 53   14031561054785509     ●   ●   ●   ●   ●   ·   ·   ●   ●   ·   ●   ·    8   0.949
 54   14296307489781462     ●   ·   ·   ·   ·   ●   ●   ·   ●   ·   ·   ·    4   0.479
 55   14561053924777415     ·   ●   ·   ●   ●   ·   ●   ·   ·   ·   ·   ·    4   0.42 
 56   14825800359773368     ●   ·   ●   ●   ●   ●   ·   ●   ·   ●   ·   ·    7   0.779
 57   15090546794769321     ●   ●   ●   ·   ·   ●   ●   ●   ●   ·   ·   ●    8   0.89 
 58   15355293229765274     ·   ●   ●   ●   ·   ●   ●   ·   ●   ·   ●   ·    7   0.607
 59   15620039664761227     ●   ·   ·   ●   ·   ·   ·   ·   ●   ●   ·   ●    5   0.515
 60   15884786099757180     ●   ●   ●   ●   ·   ·   ·   ●   ·   ·   ·   ·    5   0.811
 61   16149532534753133     ·   ·   ·   ·   ●   ●   ●   ●   ·   ·   ·   ●    5   0.256
 62   16414278969749086     ●   ●   ·   ·   ●   ●   ●   ·   ●   ●   ●   ●    9   0.84 
 63   16679025404745039     ●   ●   ●   ·   ·   ●   ●   ●   ●   ●   ●   ·    9   0.925
 64   16943771839740992     ·   ·   ●   ●   ●   ·   ●   ·   ●   ●   ●   ●    8   0.481
 65   17208518274736945     ●   ●   ●   ·   ●   ●   ·   ●   ●   ·   ●   ·    8   0.917
 66   17473264709732898     ●   ·   ·   ●   ●   ·   ●   ●   ·   ●   ·   ●    7   0.654
 67   17738011144728851     ·   ●   ●   ●   ·   ·   ·   ●   ●   ●   ●   ·    7   0.571
 68   18002757579724804     ●   ●   ·   ·   ●   ●   ●   ●   ·   ·   ·   ·    6   0.765
 69   18267504014720757     ●   ·   ·   ●   ●   ·   ·   ●   ·   ●   ·   ·    5   0.577
 70   18532250449716710     ·   ●   ●   ●   ·   ·   ·   ·   ·   ●   ●   ·    5   0.493
 71   18796996884712663     ●   ·   ●   ●   ·   ●   ·   ·   ●   ●   ●   ·    7   0.72 
 72   19061743319708616     ●   ●   ●   ·   ·   ·   ·   ·   ·   ●   ·   ●    5   0.733
 73   19326489754704569     ·   ●   ·   ·   ·   ●   ●   ·   ·   ·   ●   ●    5   0.363
 74   19591236189700522     ●   ·   ●   ·   ●   ●   ●   ●   ●   ·   ●   ●    9   0.794
 75   19855982624696475     ●   ●   ·   ●   ●   ●   ·   ·   ·   ·   ●   ·    6   0.787
 76   20120729059692428     ·   ·   ·   ·   ·   ·   ●   ●   ·   ●   ·   ·    3   0.128
 77   20385475494688381     ●   ●   ●   ●   ●   ·   ●   ·   ·   ·   ●   ●    8   0.948
 78   20650221929684334     ●   ●   ●   ●   ●   ●   ·   ·   ●   ●   ●   ●   10   1.021
 79   20914968364680287     ·   ·   ●   ·   ●   ●   ·   ●   ·   ·   ·   ·    4   0.322
 80   21179714799676240     ●   ●   ·   ●   ·   ●   ●   ●   ●   ●   ·   ●    9   0.87 
 81   21444461234672193     ●   ·   ●   ●   ●   ·   ●   ·   ●   ●   ●   ●    9   0.815
 82   21709207669668146     ·   ●   ·   ●   ●   ●   ●   ·   ●   ●   ·   ●    8   0.57 
 83   21973954104664099     ●   ●   ·   ·   ·   ·   ●   ●   ●   ·   ●   ●    7   0.715
 84   22238700539660052     ●   ·   ●   ·   ·   ·   ·   ●   ·   ·   ●   ●    5   0.571
 85   22503446974656005     ·   ●   ●   ·   ·   ●   ●   ·   ·   ·   ●   ·    5   0.481
 86   22768193409651958     ●   ·   ●   ●   ·   ·   ·   ●   ●   ·   ●   ●    7   0.696
 87   23032939844647911     ●   ●   ·   ·   ●   ·   ●   ·   ●   ●   ·   ●    7   0.754
 88   23297686279643864     ·   ●   ●   ●   ●   ●   ·   ●   ●   ·   ·   ·    7   0.647
 89   23562432714639817     ●   ·   ·   ●   ·   ·   ·   ●   ·   ·   ·   ·    3   0.468
 90   23827179149635770     ●   ●   ·   ·   ●   ●   ·   ●   ·   ●   ●   ●    8   0.796
 91   24091925584631723     ·   ·   ●   ●   ●   ●   ·   ●   ●   ·   ·   ●    7   0.472
 92   24356672019627676     ●   ●   ●   ●   ●   ●   ●   ●   ●   ·   ·   ●   10   1.058
 93   24621418454623629     ●   ●   ●   ●   ·   ·   ●   ·   ●   ●   ·   ·    7   0.886
 94   24886164889619582     ·   ·   ·   ·   ●   ·   ·   ·   ●   ●   ·   ·    3   0.144
 95   25150911324615535     ●   ●   ●   ·   ●   ●   ●   ·   ·   ●   ●   ·    8   0.924
 96   25415657759611488     ●   ·   ·   ·   ·   ●   ●   ·   ●   ·   ·   ·    4   0.479
 97   25680404194607441     ·   ●   ·   ●   ·   ●   ·   ●   ·   ●   ·   ·    5   0.425
 98   25945150629603394     ●   ●   ●   ·   ·   ·   ·   ·   ·   ●   ·   ●    5   0.733
 99   26209897064599347     ●   ·   ●   ●   ·   ●   ●   ●   ·   ·   ●   ·    7   0.749
100   26474643499595300     ·   ●   ●   ●   ●   ·   ●   ·   ●   ●   ●   ●    9   0.681
Optimum k:   23
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

Re: Slow printing speed

Post by luowy »

I do a test

Code: Select all

MODULE ObxUnicode;

	IMPORT Log := StdLog, CpcTimers;


	PROCEDURE Do* ();
		VAR i: INTEGER;
		VAR t: CpcTimers.Timer;
	BEGIN
		t.Start();
		FOR i := 0 TO 16 DO
			Log.String("●●●●●●"); Log.Tab;
		END;
		t.Stop();
		Log.Ln;
		Log.Int(t.Ticks()); Log.Ln;
		
		t.Start();
		FOR i := 0 TO 16 DO
			Log.String('' + 0D8X + 0D8X + 0D8X+ 0D8X+ 0D8X+ 0D8X); Log.Tab;
		END;
		t.Stop();
		Log.Ln;
		Log.Int(t.Ticks()); Log.Ln;
		
	END Do;

END ObxUnicode.
the output is

Code: Select all

●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	●●●●●●	
 156
ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	ØØØØØØ	
 15
about 5~10 times slow!

as far as I concerned, the slowness happened at long unicode text without linebreak,
I remember Ivan had patched this issue,I don't know if it can be improved or not.
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: Slow printing speed

Post by Ivan Denisov »

Here the trouble can be, that TextModel.Model contains many "peaces".
The space is ASCII "Piece" and ● is unicode "LPiece".
So TextModels chunk the data with many such peaces and precess them separately.
Some people think, that TextModels should be redesigned for realities of modern Unicode world. It is not ok, that spaces led to dramatic segmentation of algorithms for unicode texts.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: Slow printing speed

Post by Josef Templ »

I haven't done any benchmarks but I think that Ivan is right.
It looks very much like a fragmentation problem
of the piece-list that is at the core of the text system.
In some situations this leads to quadratic behavior, so doubling the number of pieces slows things down by a factor of 4.

I don't know the current implementation in detail but traditionally non-ascii was seen as an exceptional case that
did not need much optimization. So it is very likely that a lot of very short pieces result,
one piece is for ascii (small text size optimization) and one is for unicode (the remaining 'rare' cases that use double byte encoding).
It may be possible to introduce some larger threshold for switching back from unicode to ascii pieces.
For example, if we know that maintaining the piece list costs us 200 bytes per piece, than it may be justified to
have unicode-pieces of some minimum size, eg. 100 characters, or so without a very large overall memory overhead.

The piece lists in Oberon in general and in BlackBox in particular are quite subtle and extreme care must be taken not to screw things up.

- Josef
Last edited by Josef Templ on Thu Aug 08, 2019 10:22 pm, edited 1 time in total.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: Slow printing speed

Post by Josef Templ »

one more idea: you culd use the built-in profiler (Dev-Start Profiler) for checking out what needs most of the runtime.

- Josef
Post Reply