gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnugo-devel] order_moves speedup


From: Evan Berggren Daniel
Subject: [gnugo-devel] order_moves speedup
Date: Wed, 25 Sep 2002 11:26:50 -0400 (EDT)

This patch provides a slight speed improvement to order_moves.  It just
tunes the selection sort a little.

Thanks

Evan Daniel

Original profile (nngs2.tst):
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ks/call  Ks/call  name
  8.75    119.97   119.97 186241896     0.00     0.00  scan_for_patterns
  5.14    190.51    70.54 139094553     0.00     0.00  fastlib
  4.13    247.19    56.68   227484     0.00     0.00
compute_primary_domains
  3.63    296.96    49.77 33947501     0.00     0.00  order_moves
  3.44    344.19    47.23 120918720     0.00     0.00  check_pattern_light
  3.38    390.53    46.34 55798677     0.00     0.00  do_play_move
  3.35    436.42    45.89 77226156     0.00     0.00
incremental_order_moves
  2.99    477.47    41.05 55793059     0.00     0.00  undo_trymove
  2.66    514.01    36.54 233377721     0.00     0.00  neighbor_of_string
  2.35    546.30    32.29 34068871     0.00     0.00  assimilate_string
  2.24    576.99    30.69 150407095     0.00     0.00  approxlib


New profile:

  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ks/call  Ks/call  name
  8.67    119.05   119.05 186241896     0.00     0.00  scan_for_patterns
  5.05    188.41    69.36 139094553     0.00     0.00  fastlib
  4.25    246.74    58.33   227484     0.00     0.00
compute_primary_domains
  3.46    294.29    47.55 120918720     0.00     0.00  check_pattern_light
  3.40    340.93    46.64 33947501     0.00     0.00  order_moves
  3.39    387.53    46.60 55798677     0.00     0.00  do_play_move
  3.32    433.14    45.61 77226156     0.00     0.00
incremental_order_moves
  2.93    473.33    40.19 55793059     0.00     0.00  undo_trymove
  2.63    509.50    36.17 233377721     0.00     0.00  neighbor_of_string
  2.34    541.68    32.18 34068871     0.00     0.00  assimilate_string


Index: reading.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/reading.c,v
retrieving revision 1.72
diff -u -d -r1.72 reading.c
--- reading.c   24 Sep 2002 07:20:24 -0000      1.72
+++ reading.c   25 Sep 2002 15:22:10 -0000
@@ -5313,7 +5313,7 @@

     /* Find the move with the biggest score. */
     maxscore = moves->score[i];
-    max_at = i;
+    max_at = 0;/*this is slightly faster than max_at = i*/
     for (j = i+1; j < moves->num; j++) {
       if (moves->score[j] > maxscore) {
        maxscore = moves->score[j];
@@ -5324,15 +5324,15 @@
     /* Now exchange the move at i with the move at max_at.
      * Don't forget to exchange the scores as well.
      */
-    if (max_at != i) {
-      int temp = moves->pos[i];
-      int tempmax = moves->score[i];
+    if (max_at != 0) {

-      moves->pos[i] = moves->pos[max_at];
-      moves->score[i] = moves->score[max_at];
+      int temp = moves->pos[max_at];

-      moves->pos[max_at] = temp;
-      moves->score[max_at] = tempmax;
+      moves->pos[max_at] = moves->pos[i];
+      moves->score[max_at] = moves->score[i];
+
+      moves->pos[i] = temp;
+      moves->score[i] = maxscore;
     }
   }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]