Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: [Patch] is_city_center
Home

[Freeciv-Dev] Re: [Patch] is_city_center

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gaute B Strokkenes <gs234@xxxxxxxxx>
Cc: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>, freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: [Patch] is_city_center
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 6 Oct 2001 13:21:37 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Fri, Oct 05, 2001 at 11:20:26PM +0100, Gaute B Strokkenes wrote:
> On Tue, 2 Oct 2001, hawk@xxxxxxxxxxxxxxxxxxxxxxx wrote:
> > On Mon, Oct 01, 2001 at 08:18:33PM -0400, Ross W. Wetmore wrote:
> >> You propagated the bug Gaute introduced in the assignment of
> >> pollution.  Note, the original code skips on bad squares
> >> (preserving probabilities on a per square basis).
> > 
> > Version 1.160 (code before Gautes changes):
> > 1.67         (jjm      08-Aug-99):       x=myrand(5)-2;
> > 1.67         (jjm      08-Aug-99):       y=myrand(5)-2;
> > 1.67         (jjm      08-Aug-99):       if ( ( x != -2 && x != 2 ) || ( y 
> > != -2 && y != 2 ) ) {
> > 1.67         (jjm      08-Aug-99):      x=map_adjust_x(pcity->x+x); 
> > y=map_adjust_y(pcity->y+y);
> > 1.67         (jjm      08-Aug-99):      if ( (map_get_terrain(x,y)!=T_OCEAN 
> > && map_get_terrain(x,y)<=T_TUNDRA) &&
> > 1.67         (jjm      08-Aug-99):           
> > (!(map_get_special(x,y)&S_POLLUTION)) ) {
> > 
> > This is bad.
> 
> Yes, but not for the reason claimed.  Note the call to map_adjust_y().
> 
> > What do you think about
> > 
> > +      int cx = myrand(CITY_MAP_SIZE);
> > +      int cy = myrand(CITY_MAP_SIZE);
> > +
> > +      if (is_valid_city_coords(cx, cy)) {
> > +       int x, y;
> > +
> > +       if (!city_map_to_map(&x, &y, pcity, cx, cy)) {
> >           continue;
> > +       }
> > ?
> 
> I think that looks a lot better.  But please profile it.

I applied the patch already. You are a bit slow ;)

Ok here is the profile from the current version (with exact
descriptions of the steps):

$ make clean
...
$ alias makeep
alias makeep='make CPPFLAGS="-Wall -Wpointer-arith -Wcast-align 
-Wmissing-prototypes -Wmissing-declarations -Werror" CFLAGS="-O2 -g -pg"'
$ makeep
...
$ cat profile.rc
set randseed 42       # repeat a particular game (random) sequence
set seed 42           # repeat a particular map generation sequence
set timeout -1          # run a server only autogame
set aifill 7            # fill to 7 players
set endyear 2000
hard                    # make the AI do complex things
create Caesar           # first player (with known name) created and
                        # toggled to AI mode
start
$ ./ser -r ./profile.rc
...
$ gprof server/civserver
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 14.34     62.04    62.04 1363143323     0.00     0.00  normalize_map_pos
  9.56    103.39    41.35    89021     0.46     0.71  really_generate_warmap
  3.39    118.06    14.67 276149384     0.00     0.00  tech_exists
  2.67    129.62    11.56 114416988     0.00     0.00  map_get_city
  2.53    140.55    10.93 161998981     0.00     0.00  map_get_terrain
  2.44    151.10    10.55 261080172     0.00     0.00  map_get_tile
  2.12    160.29     9.19 105205024     0.00     0.00  base_city_map_to_map
  2.08    169.30     9.01 252198709     0.00     0.00  get_invention
  1.75    176.87     7.57 166417826     0.00     0.00  unit_type_flag
  1.63    183.90     7.03 214016014     0.00     0.00  is_real_tile
  1.62    190.90     7.00  3556081     0.00     0.00  road_bonus
  1.53    197.50     6.60 173730010     0.00     0.00  is_valid_city_coords
  1.42    203.65     6.15    24605     0.25     2.58  evaluate_improvements
  1.35    209.48     5.83 113274165     0.00     0.00  improvement_exists
  1.22    214.77     5.29 71414248     0.00     0.00  map_get_continent
  1.15    219.73     4.96 52337249     0.00     0.00  get_from_mapqueue
  1.14    224.67     4.94  1652114     0.00     0.01  
player_knows_techs_with_flag
  1.09    229.39     4.72 130350656     0.00     0.00  city_owner
  1.09    234.10     4.71 83897969     0.00     0.00  city_got_building
  1.07    238.73     4.63 68098747     0.00     0.00  map_get_special
  1.05    243.28     4.55 66555959     0.00     0.00  get_worker_city
  1.05    247.81     4.53 104533466     0.00     0.00  genlist_iterator_init
  1.02    252.23     4.42 52226566     0.00     0.00  add_to_mapqueue
  1.02    256.63     4.40 104537909     0.00     0.00  find_genlist_position
  1.02    261.03     4.40 12058842     0.00     0.00  city_get_food_tile
...
  0.19    389.78     0.83   395806     0.00     0.01  is_square_threatened
  0.19    390.59     0.81 29956701     0.00     0.00  is_city_center
  0.19    391.40     0.81 22819390     0.00     0.00  is_sailing_unit
...
  0.00    432.55     0.00    22532     0.00     0.93  ai_manage_city
  0.00    432.55     0.00    22532     0.00     0.00  check_pollution
  0.00    432.55     0.00    22532     0.00     0.00  city_build_stuff
...
granularity: each sample hit covers 4 byte(s) for 0.00% of 432.55 seconds

index % time    self  children    called     name
...
-----------------------------------------------
                0.00    0.00    8920/29956701     city_can_work_tile [267]
                0.00    0.00  136853/29956701     auto_arrange_workers [51]
                0.01    0.00  473172/29956701     worst_worker_tile_value [235]
                0.01    0.00  478128/29956701     best_worker_tile_value [154]
                0.10    0.00 3683505/29956701     ai_find_elvis_pos [53]
                0.13    0.00 4638588/29956701     city_desirability [98]
                0.21    0.00 7881157/29956701     city_get_shields_tile [35]
                0.34    0.00 12656378/29956701     city_get_food_tile [32]
[230]    0.2    0.81    0.00 29956701         is_city_center [230]
-----------------------------------------------
...
-----------------------------------------------
                0.00    0.00   22532/22532       update_city_activity [109]
[754]    0.0    0.00    0.00   22532         check_pollution [754]
                0.00    0.00     300/448553      myrand [329]
                0.00    0.00      12/41301550     city_map_to_map [73]
                0.00    0.00      22/161998981     map_get_terrain [42]
                0.00    0.00      10/163100      map_set_special [486]
                0.00    0.00      10/1164        send_tile_info [746]
                0.00    0.00      10/10602       notify_player_ex [666]
                0.00    0.00      10/68098747     map_get_special [82]
                0.00    0.00      15/173730010     is_valid_city_coords [95]
                0.00    0.00      10/130350656     city_owner [115]
-----------------------------------------------

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Life is too short for reboots."


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