type List_Node
bus_stop::Bus_Stop
bus_stops::Dict{Int64, Bus_Stop}

next::List_Node
prev::List_Node

num_next::Int64
num_prev::Int64

distance_to_next::Float64
distance_to_prev::Float64

function List_Node(bus_stop::Bus_Stop)
list_node = new()
list_node.bus_stop = bus_stop
list_node.bus_stops = Dict{Int64, Bus_Stop}()
list_node.bus_stops[bus_stop.id] = bus_stop
list_node.next = list_node
list_node.prev = list_node
list_node.num_next = -1
list_node.num_prev = -1
list_node.distance_to_next = 0.0
list_node.distance_to_prev = 0.0
list_node
end
end

abstract EdgeAbstract

type Bus_Stop
id::Int64
name::ASCIIString
latitude::Float64
longitude::Float64

#edges::ObjectIdDict
edges::Dict{Bus_Stop, EdgeAbstract}

Bus_Stop(id::Int64) = (bs = new(); bs.id = id; bs)
end

type Edge <: EdgeAbstract
 src::Bus_Stop
tar::Bus_Stop
speed::Float64
distance::Float64

function Edge(src::Bus_Stop, tar::Bus_Stop, distance::Float64, 
speed::Float64)
edge = new()
edge.src = src
edge.tar = tar
edge.distance = distance
edge.speed = speed
edge
end
end

function summation_time(origin_node::List_Node, destination_node::List_Node)
    tmp = 0.0
    
    current_node = origin_node
    while current_node != destination_node

        src_bus_stop = current_node.bus_stop 
        tar_bus_stop = current_node.next.bus_stop

        edge = src_bus_stop.edges[tar_bus_stop]
        tmp += edge.distance / edge.speed
    
        current_node = current_node.next
    end
    
    return tmp
end

I noticed calling the summation_time function repeatedly degrades the 
performance... Anything wrong in what I did ?

On Tuesday, April 1, 2014 10:43:52 PM UTC+8, Stefan Karpinski wrote:
>
> If you can provide some example code, lots of people here are more than 
> happy to help performance optimize it, but without example code, it's hard 
> to give you anything more specific than don't allocate more than you have 
> to and don't make copies of things if you don't have to. Using mutating 
> APIs (functions with ! at the end) is helpful. The Dict itself isn't 
> allocating small objects on the heap, but you may very well be generating a 
> lot of garbage along the way. 
>
>

Reply via email to