\ifdef Oz_2
\sw -threadedqueries
\endif

declare
MIO=1000000
proc {Skip}
\ifdef Oz_2
   skip
\else
   true
\end
end
proc {MyLoop N P}
   case N of 0 then
      {Skip}
   else
      {P}
      {MyLoop N-1 P}
   end
end
fun {GetTime}
   {Int.toFloat
\ifdef Oz_2
    {System.get time}
    .run
%    .total
\else
   {System.userTime}
\endif
   }
   /1000.0
end
fun {TestH N P}
   thread
      {System.gcDo} {System.gcDo}
      S={GetTime}
   in
      {MyLoop N P}
      ({GetTime}-S)/{Int.toFloat N}
   end
end
fun {Test I N P1 P2}
   N1={TestH N P1}
\ifdef Oz_2   
   {Wait N1}
   N2={TestH N P2}
\else
   N2=if {Det N1} then
      {TestH N P2}
   fi
\end
in
   (N2-N1)/{Int.toFloat I}
end

\ifdef MMM

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HO appl

local
   proc {T1aa P}
      {P} {P} {P} {P}
   end
   proc {T1a} {T1aa Skip} end
   proc {T1bb P}
      {P} {P} {P} {P}
      {P} {P} {P} {P}
   end
   proc {T1b} {T1bb Skip} end
   T = {Test 4 MIO T1a T1b}
in
   {System.showInfo 'HO appl: '#T#'sec = '#1.0/T#' appl/sec'}
end

%               time [us]    	mio appl/sec
% hardy         0.8		1.25
%		0.77		1.30
% hardy (t)	0.84		1.2
%		0.81		1.22
% munchkin      0.6             1.7
%		0.6		1.8
% munchkin (t)	0.6		1.7
%		0.6		1.7
% emerald       0.025		40
%		0.026		38.8
%               0.0043		235.3
% emerald (t)   0.4             2.5
%		0.25		4.0
%		0.46		2.2
%		0.21		4.9
%		0.38		2.7
%		0.43		2.3
% glinda (t)    1.0		0.97
%		1.1		0.88
% glinda	1.1		0.90
%		1.0		0.99
%		1.1		0.95
%		1.1		0.93
% glinda 1.1    1.2		0.82
%		1.2		0.83

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% opt. appl

local
   proc {T2a}
      {Skip} {Skip} {Skip} {Skip}
   end
   proc {T2b}
      {Skip} {Skip} {Skip} {Skip}
      {Skip} {Skip} {Skip} {Skip}
   end
   T={Test 4 MIO T2a T2b}
in
   {System.showInfo 'opt appl: '#T#'sec = '#1.0/T#' appl/sec'}
end
%               time [us]    	mio appl/sec
% hardy    	0.34       	3
% munchkin      0.32            3.2
%		0.32		3.1
% glinda	0.50		2.0
%		0.49		2.0
% glinda 1.1	0.87		1.15
%		0.87		1.15



local
   proc {P X} {Skip} end
   proc {T2a}
      X in
      {P X}
      {P P}
      {Skip}
   end
   proc {T2b}
      X in
      {P X}
      {Skip}
      {P X}
   end
   T={Test 1 MIO T2a T2b}
in
   {System.showInfo 'env: '#T#'sec = '#1.0/T#' appl/sec'}
end
%               time [us]    	mio appl/sec
% hardy		0.94		1.1
%		0.88		1.1
%		0.84		1.2
%		0.8		1.3
%		0.82		1.2
%		0.84		1.2
% glinda	0.39		2.6
%		0.48		2.1
%		0.39		2.6
%		0.48		2.1
%		0.42		2.4
% glinda 1.1	0.38		2.6
%		0.37		2.7
%		0.40		2.5

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% with 1 arg


local
   proc {Skip1 X}
\ifdef Oz_2
      skip
\else
      true
\endif
   end
   proc {T3a}
      {Skip1 1} {Skip1 1} {Skip1 1} {Skip1 1}
   end
   proc {T3b}
      {Skip1 1} {Skip1 1} {Skip1 1} {Skip1 1}
      {Skip1 1} {Skip1 1} {Skip1 1} {Skip1 1}
   end
   T={Test 4 MIO T3a T3b}
in
   {System.showInfo 'opt appl 1 arg: '#T#'sec = '#1.0/T#' appl/sec'}
end

%               time [us]    	mio appl/sec
% hardy         0.35            2.8
% munchkin      0.4      	2.5
%		0.43		2.3
% glinda	0.58		1.7
%		0.60		1.7
% glinda 1.1	1.0		1.0
%		0.97		1.0

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% with 2 args

local
   proc {Skip2 X Y}
\ifdef Oz_2
      skip
\else
      true
\endif
   end
   proc {T4a}
      {Skip2 1 1} {Skip2 1 1} {Skip2 1 1} {Skip2 1 1}
   end
   proc {T4b}
      {Skip2 1 1} {Skip2 1 1} {Skip2 1 1} {Skip2 1 1}
      {Skip2 1 1} {Skip2 1 1} {Skip2 1 1} {Skip2 1 1}
   end
   T={Test 4 MIO T4a T4b}
in
   {System.showInfo 'opt appl 2 arg: '#T#'sec = '#1.0/T#' appl/sec'}
end
%               time [us]    	mio appl/sec
% hardy         0.43            2.3
% munchkin      0.42		2.4
%		0.51		1.97
%		0.50		2.01
%		0.50		2.01
% glinda	0.69		1.45
%		0.70		1.43
% glinda 1.1	1.07		0.93
%		1.07		0.94


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1+1

local
   proc {Ta}
      _=1+1 _=1+1 _=1+1 _=1+1
   end
   proc {Tb}
      _=1+1 _=1+1 _=1+1 _=1+1
      _=1+1 _=1+1 _=1+1 _=1+1
   end
   T={Test 4 MIO Ta Tb}
in
   {System.showInfo '1+1: '#T#'sec = '#1.0/T#' appl/sec'}
end

%               time [us]    	mio appl/sec
% munchkin	0.44		2.3
% 	  	0.40		2.5
%          	0.42		2.4
% hardy		0.37		2.7
% glinda	0.54		1.84
%		0.55		1.82
% glinda 1.1    0.62		1.6
%		0.42		2.4
%		0.73		1.4

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 10+10

local
   proc {Ta}
      _=10+10 _=10+10 _=10+10 _=10+10
   end
   proc {Tb}
      _=10+10 _=10+10 _=10+10 _=10+10
      _=10+10 _=10+10 _=10+10 _=10+10
   end
   T={Test 4 MIO Ta Tb}
in
   {System.showInfo '10+10: '#T#'sec = '#1.0/T#' appl/sec'}
end
%               time [us]    	mio appl/sec
% hardy         0.43            2.3
%		0.56		1.8
%		0.57		1.8
% munchkin      0.57            1.7
% 		0.53            1.9
% 		0.54            1.8
%		0.54		1.8
% glinda	0.75		1.3
%		0.75		1.3
% glinda 1.1	1.77		0.6
%		1.4		0.7


local
   proc {Ta}
      _=10.0*10.0 _=10.0*10.0 _=10.0*10.0 _=10.0*10.0
   end
   proc {Tb}
      _=10.0*10.0 _=10.0*10.0 _=10.0*10.0 _=10.0*10.0
      _=10.0*10.0 _=10.0*10.0 _=10.0*10.0 _=10.0*10.0
   end
   T={Test 4 MIO Ta Tb}
in
   {System.showInfo '10.0*10.0: '#T#'sec = '#1.0/T#' appl/sec'}
end
%               time [us]    	mio appl/sec
% glinda	0.94		1.1
%		0.93		1.1
% glinda 1.1	1.1		0.9
%		1.2		0.9

local
   proc {Taa X}
      case X of a then a=a end
      case X of a then a=a end
      case X of a then a=a end
      case X of a then a=a end
   end
   proc {Ta} {Taa a} end
   proc {Tbb X}
      case X of a then a=a end
      case X of a then a=a end
      case X of a then a=a end
      case X of a then a=a end
      case X of a then a=a end
      case X of a then a=a end
      case X of a then a=a end
      case X of a then a=a end
   end
   proc {Tb} {Tbb a} end
   T={Test 4 MIO Ta Tb}
in
   {System.showInfo 'case X of a then: '#T#'sec = '#1.0/T#' case/sec'}
end
%               time [us]    	mio case/sec
% glinda	0.25		4.0
%		0.25		4.0
% glinda 1.1	0.92		1.1
%		0.90		1.1


local
   proc {Taa X}
      case X of a then a=a [] b then a=a []c then a=a end
      case X of a then a=a [] b then a=a []c then a=a end
      case X of a then a=a [] b then a=a []c then a=a end
      case X of a then a=a [] b then a=a []c then a=a end
   end
   proc {Ta} {Taa b} end
   proc {Tbb X}
      case X of a then a=a [] b then a=a []c then a=a end
      case X of a then a=a [] b then a=a []c then a=a end
      case X of a then a=a [] b then a=a []c then a=a end
      case X of a then a=a [] b then a=a []c then a=a end
      case X of a then a=a [] b then a=a []c then a=a end
      case X of a then a=a [] b then a=a []c then a=a end
      case X of a then a=a [] b then a=a []c then a=a end
      case X of a then a=a [] b then a=a []c then a=a end
   end
   proc {Tb} {Tbb b} end
   T={Test 4 MIO Ta Tb}
in
   {System.showInfo 'case X of a [] b [] c: '#T#'sec = '#1.0/T#' case/sec'}
end
%               time [us]    	mio case/sec
% glinda	0.51		2.0
% glinda 1.1	1.2		0.85
%		1.2		0.85


local
   proc {Ta}
      try skip catch failure(_) then skip end
      try skip catch failure(_) then skip end
      try skip catch failure(_) then skip end
      try skip catch failure(_) then skip end
   end
   proc {Tb}
      try skip catch failure(_) then skip end
      try skip catch failure(_) then skip end
      try skip catch failure(_) then skip end
      try skip catch failure(_) then skip end
      try skip catch failure(_) then skip end
      try skip catch failure(_) then skip end
      try skip catch failure(_) then skip end
      try skip catch failure(_) then skip end
   end
   T={Test 4 MIO Ta Tb}
in
   {System.showInfo 'try catch: '#T#'sec = '#1.0/T#' case/sec'}
end
%               time [us]    	mio try/sec
% glinda	0.7		1.4


local
   proc {Ta}
      try skip finally skip end
      try skip finally skip end
      try skip finally skip end
      try skip finally skip end
   end
   proc {Tb}
      try skip finally skip end
      try skip finally skip end
      try skip finally skip end
      try skip finally skip end
      try skip finally skip end
      try skip finally skip end
      try skip finally skip end
      try skip finally skip end
   end
   T={Test 4 MIO Ta Tb}
in
   {System.showInfo 'try finally: '#T#'sec = '#1.0/T#' case/sec'}
end
%               time [us]    	mio try/sec
% glinda	2.1		0.48
%		1.8		0.54



local
   C={NewCell C}
   proc {Ta}
      {Exchange C C C} {Exchange C C C} {Exchange C C C} {Exchange C C C}
   end
   proc {Tb}
      {Exchange C C C} {Exchange C C C} {Exchange C C C} {Exchange C C C}
      {Exchange C C C} {Exchange C C C} {Exchange C C C} {Exchange C C C}
   end
   T={Test 4 100000 Ta Tb}
in
   {System.showInfo 'Exchange: '#T#'sec = '#1.0/T#' exch/sec'}
end
%               time [us]    	mio appl/sec
% glinda	1.7		0.59
%		1.7		0.58
% glinda 1.1	2.6		0.38
%		2.7		0.37
%		2.6		0.39

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% threads

local
\ifdef Oz_2
   proc {Ta}
      thread skip end thread skip end thread skip end thread skip end
   end
   proc {Tb}
      thread skip end thread skip end thread skip end thread skip end
      thread skip end thread skip end thread skip end thread skip end
   end
\else
   proc {Ta}
      thread true end thread true end thread true end thread true end
   end
   proc {Tb}
      thread true end thread true end thread true end thread true end
      thread true end thread true end thread true end thread true end
   end
\endif   
   T={Test 4 100000 Ta Tb}
in
   {System.showInfo 'thread skip end: '#T#'sec = '#1.0/T#' threads/sec'}
end
%               time [us]    	thousand threads/sec
% munchkin	3.4		292
%		3.6		278
%		2.9             344
%               2.6             384
% hardy         7.3             137
% glinda	6.6		152
%		6.9		145
% glinda 1.1	10.0		97
%		9.7		103

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% threads

local
\ifdef Oz_2
   proc {Ta}
      thread {Wait _} end thread {Wait _} end
      thread {Wait _} end thread {Wait _} end
   end
   proc {Tb}
      thread {Wait _} end thread {Wait _} end
      thread {Wait _} end thread {Wait _} end
      thread {Wait _} end thread {Wait _} end
      thread {Wait _} end thread {Wait _} end
   end
\else
   proc {Ta}
      thread {Det _} end thread {Det _} end
      thread {Det _} end thread {Det _} end
   end
   proc {Tb}
      thread {Det _} end thread {Det _} end
      thread {Det _} end thread {Det _} end
      thread {Det _} end thread {Det _} end
      thread {Det _} end thread {Det _} end
   end
\endif
   T={Test 4 100000 Ta Tb}
in
   {System.showInfo 'thread {Wait _} end: '#T#'sec = '#1.0/T#' threads/sec'}
end
%               time [us]    	thousand threads/sec
% munchkin	4.9		203
%		5.2		191
%		5.6             177
% hardy		8.5             118
%               8.2		122
% glinda	9.1		110
%		9.3		108
% glinda 1.1	13.6		74
%		15.1		66



local
   class C
\ifndef Oz_2
      from UrObject
\endif
      meth noop a=a end end
   O = {New C noop}
   proc {T1a}
      {O noop} {O noop} {O noop} {O noop}
   end
   proc {T1b}
      {O noop} {O noop} {O noop} {O noop}
      {O noop} {O noop} {O noop} {O noop}
   end
   T = {Test 4 MIO T1a T1b}
in
   {System.showInfo '{O noop}: '#T#'sec = '#1.0/T#' appl/sec'}
end
%               time [us]    	thousand obj. appl/sec
% glinda	1.3		780
% glinda 1.1	3.2		314
%		3.0		328

local
   class C
\ifndef Oz_2
      from UrObject
\endif
      meth noop a=a end
      meth a
         {self noop} {self noop} {self noop} {self noop}
      end
      meth b
         {self noop} {self noop} {self noop} {self noop}
         {self noop} {self noop} {self noop} {self noop}
      end
   end
   O={New C noop}
   proc {Ta} {O a} end
   proc {Tb} {O b} end
   T = {Test 4 MIO Ta Tb}
in
   {System.showInfo '{self noop}: '#T#'sec = '#1.0/T#' appl/sec'}
end
%               time [us]    	self appl/sec
% glinda	1.1		900,000
% glinda 1.1	3.1		320,000


local
   class C
      meth noop a=a end
      meth a
         C,noop C,noop C,noop C,noop
      end
      meth b
         C,noop C,noop C,noop C,noop
         C,noop C,noop C,noop C,noop
      end
   end
   O={New C noop}
   proc {Ta} {O a} end
   proc {Tb} {O b} end
   T = {Test 4 MIO Ta Tb}
in
   {System.showInfo 'C,noop: '#T#'sec = '#1.0/T#' appl/sec'}
end
\ifdef Oz_2
local
   class C
      from UrObject
      meth noop a=a end
      meth a
         <<C noop>> <<C noop>> <<C noop>> <<C noop>>
      end
      meth b
         <<C noop>> <<C noop>> <<C noop>> <<C noop>>
         <<C noop>> <<C noop>> <<C noop>> <<C noop>>
      end
   end
   O={New C noop}
   proc {Ta} {O a} end
   proc {Tb} {O b} end
   T = {Test 4 100000 Ta Tb}
in
   {System.showInfo 'C,noop: '#T#'sec = '#1.0/T#' appl/sec'}
end
\endif
%               time [us]    	mio class appl/sec
% glinda	0.5		1.980
%		0.5		2.000
%		0.47		2.151
% glinda 1.1	3.15		0.317
%		2.88		0.348

local
   class C
\ifndef Oz_2
      from UrObject
\endif
      attr a
      meth noop a=a end
      meth a
         _=@a _=@a _=@a _=@a
      end
      meth b
         _=@a _=@a _=@a _=@a
         _=@a _=@a _=@a _=@a
      end
   end
   O={New C noop}
   proc {Ta} {O a} end
   proc {Tb} {O b} end
   T = {Test 4 MIO Ta Tb}
in
   {System.showInfo '@a: '#T#'sec = '#1.0/T#' access/sec'}
end
%               time [us]    	mio class appl/sec
% glinda	0.27		3.7
%		0.29		3.4
%		0.30		3.4
% glinda 1.1	1.3		0.8
%		1.3		0.8

local
   class C
\ifndef Oz_2
      from UrObject
\endif
      attr a
      meth noop a=a end
      meth a(X)
         a<-X a<-X a<-X a<-X
      end
      meth b(X)
         a<-X a<-X a<-X a<-X
         a<-X a<-X a<-X a<-X
      end
   end
   O={New C noop}
   proc {Ta} {O a(1)} end
   proc {Tb} {O b(1)} end
   T = {Test 4 MIO Ta Tb}
in
   {System.showInfo 'a<-: '#T#'sec = '#1.0/T#' assign/sec'}
end
%               time [us]    	mio assign/sec
% glinda	0.24		4.2
%		0.25		3.9
% glinda 1.1	1.1		0.9
%		1.1		0.9

local
   class C
\ifndef Oz_2
      from UrObject
\endif
      meth noop a=a end
   end
   proc {Ta}
      _={New C noop}
      _={New C noop}
      _={New C noop}
      _={New C noop}
   end
   proc {Tb}
      _={New C noop}
      _={New C noop}
      _={New C noop}
      _={New C noop}
      _={New C noop}
      _={New C noop}
      _={New C noop}
      _={New C noop}
   end
   T = {Test 4 100000 Ta Tb}
in
   {System.showInfo '{New C noop}: '#T#'sec = '#1.0/T#' appl/sec'}
end
%               time [us]    	objects/sec
% glinda	5.7		180,000
%		6.2		160,000
%		5.7		175,000
% glinda 1.1	104.2		  9,600
%               

local
   L={NewLock}
   proc {Ta}
      lock L then skip end
   end
   proc {Tb}
      lock L then skip end
      lock L then skip end
   end
   T = {Test 1 MIO Ta Tb}
in
   {System.showInfo 'lock: '#T#'sec = '#1.0/T#' locks/sec'}
end
%               time [us]    	mio lock/sec
% glinda	1.5		0.66
%		1.5		0.68