diff: Bug fix in diff and performance results

Andrew Bromage bromage at cs.mu.OZ.AU
Thu Sep 24 18:22:55 AEST 1998


G'day all.

This will be committed if nobody objects in the next couple of days.

Attached after the diff are some not-very-scientific performance results,
recorded on a medium-loaded mercury.cs.mu.oz.au.  The sizes of the two
files being diffed and the size of the actual diff are included for
comparison.

Cheers,
Andrew Bromage


Estimated hours taken: 2

Bug fix in diff.

samples/diff/diff_out.m:
	In a unified diff, there was some repeated output due to the
	last position of a diff not being retrieved correctly.  (In
	fact, it was the _first_ position which was being retrieved.
	D'oh!)

samples/diff/*.m:
	Exploited a few opportunities to use conditional expressions
	for conciseness.

Index: diff_out.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/samples/diff/diff_out.m,v
retrieving revision 1.2
diff -u -t -u -r1.2 diff_out.m
--- diff_out.m	1998/09/15 04:54:22	1.2
+++ diff_out.m	1998/09/24 07:17:05
@@ -615,11 +615,11 @@
                 { Next = X }
         ; { Edit = delete(X1 - X2, _) },
                 diff_out__show_file(File1, DelStr, X1, X2),
-                { Next = X1 }
+                { Next = X2 }
         ; { Edit = change(X1 - X2, Y1 - Y2) },
                 diff_out__show_file(File1, DelStr, X1, X2),
                 diff_out__show_file(File2, AddStr, Y1, Y2),
-                { Next = X1 }
+                { Next = X2 }
         ),
         display_unified_diff_3(Next, Size1, File1, File2, Diff,
                                 NoneStr, AddStr, DelStr).
@@ -766,19 +766,14 @@
                 %     factor this in.
         { Off is (Width0 + 4) // 8 * 4 },
         { Max is Off - 3 },
-        { HalfWidth0 is Width0 - Off + 1 },
-        { HalfWidth0 =< 0 ->
-                HalfWidth = 0
-        ; HalfWidth0 > Max ->
-                HalfWidth = Max
-        ;
-                HalfWidth = HalfWidth0
-        },
-        { HalfWidth > 0 ->
-                Col2Off = Off
-        ;
-                Col2Off = Width0
+        { HalfWidth0 = Width0 - Off + 1 },
+        { HalfWidth =
+                (if HalfWidth0 =< 0 then 0
+                else if HalfWidth0 > Max then Max
+                else HalfWidth0
+                )
         },
+        { Col2Off = (if HalfWidth > 0 then Off else Width0) },
         globals__io_lookup_bool_option(left_column, LeftCol),
         globals__io_lookup_bool_option(suppress_common_lines, Suppress),
         globals__io_lookup_bool_option(sdiff_merge_assist, Sdiff),
@@ -988,10 +983,9 @@
                                 % If we're expanding tabs, we just pretend that
                                 % we had Spaces spaces and write them.
                                 { TabStop0 is OutPos0 + Spaces },
-                                { TabStop0 > OutBound ->
-                                        TabStop = OutBound
-                                ;
-                                        TabStop = TabStop0
+                                { TabStop =
+                                        (if TabStop0 > OutBound
+                                        then OutBound else TabStop0)
                                 },
                                 put_spaces(TabStop - OutPos0, OutPos0, OutPos1)
                         ;
Index: myers.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/samples/diff/myers.m,v
retrieving revision 1.1
diff -u -t -u -r1.1 myers.m
--- myers.m	1998/09/15 04:54:36	1.1
+++ myers.m	1998/09/24 07:15:11
@@ -160,11 +160,7 @@
         Bmid = Xhigh - Yhigh,
         array__set(Bwd0, Bmid + DOffset, Xhigh, Bwd1),
 
-        ( 1 = (Fmid - Bmid) /\ 1 ->
-                DeltaOdd = yes
-        ;
-                DeltaOdd = no
-        ),
+        DeltaOdd = (if (Fmid - Bmid) /\ 1 = 1 then yes else no),
 
         Constants = constants(
                 DOffset, FileX, FileY, Xlow, Xhigh, Ylow, Yhigh,
@@ -237,11 +233,7 @@
                 Constants = constants(DOffset, _, _, _, _, _, _, _, _, _, _),
                 array__lookup(Fwd0, SearchCost + DOffset - 1, Tlo),
                 array__lookup(Fwd0, SearchCost + DOffset + 1, Thi),
-                ( Tlo >= Thi ->
-                        X0 = Tlo + 1
-                ;
-                        X0 = Thi
-                ),
+                X0 = (if Tlo >= Thi then Tlo + 1 else Thi),
                 Y0 = X0 - SearchCost,
                 Constants = constants(_, FileX, FileY, _, Xhigh, _, Yhigh,
                         _, _, _, _),
@@ -286,11 +278,7 @@
                 Constants = constants(DOffset, _, _, _, _, _, _, _, _, _, _),
                 array__lookup(Bwd0, SearchCost + DOffset - 1, Tlo),
                 array__lookup(Bwd0, SearchCost + DOffset + 1, Thi),
-                ( Tlo < Thi ->
-                        X0 = Tlo
-                ;
-                        X0 = Thi - 1
-                ),
+                X0 = (if Tlo < Thi then Tlo else Thi - 1),
                 Y0 = X0 - SearchCost,
                 Constants = constants(_, FileX, FileY, Xlow, _, Ylow, _,
                         _, _, _, _),


Test 1:
File sizes: 4 4
Size of diff:       6

Mercury diff
0.05u 0.04s 0:00.20e 45%CPU
0.05u 0.04s 0:00.09e 100%CPU
0.04u 0.05s 0:00.09e 100%CPU

GNU diff
0.00u 0.01s 0:00.03e 33%CPU
0.00u 0.01s 0:00.03e 33%CPU
0.00u 0.02s 0:00.04e 50%CPU

Test 2:
File sizes: 1 1
Size of diff:       0

Mercury diff
0.03u 0.06s 0:00.09e 100%CPU
0.07u 0.02s 0:00.09e 100%CPU
0.04u 0.05s 0:00.09e 100%CPU

GNU diff
0.01u 0.01s 0:00.03e 66%CPU
0.00u 0.01s 0:00.04e 25%CPU
0.01u 0.01s 0:00.03e 66%CPU

Test 3:
File sizes: 2 3
Size of diff:       2

Mercury diff
0.04u 0.05s 0:00.09e 100%CPU
0.05u 0.04s 0:00.09e 100%CPU
0.04u 0.05s 0:00.09e 100%CPU

GNU diff
0.00u 0.01s 0:00.04e 25%CPU
0.00u 0.02s 0:00.03e 66%CPU
0.00u 0.01s 0:00.03e 33%CPU

Test 4:
File sizes: 1 1
Size of diff:       4

Mercury diff
0.04u 0.04s 0:00.09e 88%CPU
0.06u 0.03s 0:00.09e 100%CPU
0.04u 0.04s 0:00.09e 88%CPU

GNU diff
0.01u 0.00s 0:00.03e 33%CPU
0.01u 0.01s 0:00.03e 66%CPU
0.01u 0.01s 0:00.06e 33%CPU

Test 5:
File sizes: 51 54
Size of diff:      18

Mercury diff
0.04u 0.06s 0:00.10e 100%CPU
0.04u 0.05s 0:00.10e 90%CPU
0.06u 0.04s 0:00.10e 100%CPU

GNU diff
0.00u 0.01s 0:00.03e 33%CPU
0.01u 0.00s 0:00.06e 16%CPU
0.00u 0.01s 0:00.03e 33%CPU

Test 6:
File sizes: 4067 4065
Size of diff:      34

Mercury diff
0.41u 0.06s 0:00.47e 100%CPU
0.41u 0.06s 0:00.47e 100%CPU
0.40u 0.07s 0:00.48e 97%CPU

GNU diff
0.04u 0.04s 0:00.09e 88%CPU
0.06u 0.01s 0:00.24e 29%CPU
0.02u 0.05s 0:00.11e 63%CPU

Test 7:
File sizes: 283 237
Size of diff:     522

Mercury diff
0.22u 0.03s 0:00.25e 100%CPU
0.21u 0.04s 0:00.26e 96%CPU
0.21u 0.04s 0:00.25e 100%CPU

GNU diff
0.03u 0.01s 0:00.06e 66%CPU
0.02u 0.01s 0:00.06e 50%CPU
0.03u 0.00s 0:00.18e 16%CPU




More information about the developers mailing list