mirror of
https://github.com/status-im/simulation.git
synced 2025-02-22 11:58:06 +00:00
Use NumNodes/NumLinks
This commit is contained in:
parent
10702e39b7
commit
7f4f201964
@ -27,7 +27,7 @@ func simulationHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
|
|
||||||
log.Printf("Loaded graph with %d nodes", len(data.Nodes()))
|
log.Printf("Loaded graph with %d nodes", data.NumNodes())
|
||||||
sim := NewSimulation(data)
|
sim := NewSimulation(data)
|
||||||
sim.Start()
|
sim.Start()
|
||||||
defer sim.Stop()
|
defer sim.Stop()
|
||||||
|
@ -33,7 +33,7 @@ func main() {
|
|||||||
sim.WriteOutputToFile(*output)
|
sim.WriteOutputToFile(*output)
|
||||||
|
|
||||||
// stats
|
// stats
|
||||||
ss := stats.Analyze(sim.plog, len(data.Nodes()), len(data.Links()))
|
ss := stats.Analyze(sim.plog, data.NumNodes(), data.NumLinks())
|
||||||
ss.PrintVerbose()
|
ss.PrintVerbose()
|
||||||
|
|
||||||
log.Printf("Written propagation data into %s", *output)
|
log.Printf("Written propagation data into %s", *output)
|
||||||
|
@ -37,6 +37,6 @@ func main() {
|
|||||||
log.Fatalf("Parsing propagation log failed: %v", err)
|
log.Fatalf("Parsing propagation log failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ss := stats.Analyze(plog, len(data.Nodes()), len(data.Links()))
|
ss := stats.Analyze(plog, data.NumNodes(), data.NumLinks())
|
||||||
ss.PrintVerbose()
|
ss.PrintVerbose()
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ type Message struct {
|
|||||||
|
|
||||||
// NewSimulator initializes new simulator for the given graph data.
|
// NewSimulator initializes new simulator for the given graph data.
|
||||||
func NewSimulator(data *graph.Graph, N int, delay time.Duration) *Simulator {
|
func NewSimulator(data *graph.Graph, N int, delay time.Duration) *Simulator {
|
||||||
nodeCount := len(data.Nodes())
|
nodeCount := data.NumNodes()
|
||||||
sim := &Simulator{
|
sim := &Simulator{
|
||||||
data: data,
|
data: data,
|
||||||
delay: delay,
|
delay: delay,
|
||||||
|
@ -39,7 +39,7 @@ func NewSimulator(data *graph.Graph) *Simulator {
|
|||||||
MinimumAcceptedPOW: 0.001,
|
MinimumAcceptedPOW: 0.001,
|
||||||
}
|
}
|
||||||
|
|
||||||
whispers := make(map[enode.ID]*whisper.Whisper, len(data.Nodes()))
|
whispers := make(map[enode.ID]*whisper.Whisper, data.NumNodes())
|
||||||
services := map[string]adapters.ServiceFunc{
|
services := map[string]adapters.ServiceFunc{
|
||||||
"shh": func(ctx *adapters.ServiceContext) (node.Service, error) {
|
"shh": func(ctx *adapters.ServiceContext) (node.Service, error) {
|
||||||
return whispers[ctx.Config.ID], nil
|
return whispers[ctx.Config.ID], nil
|
||||||
@ -51,15 +51,13 @@ func NewSimulator(data *graph.Graph) *Simulator {
|
|||||||
DefaultService: "shh",
|
DefaultService: "shh",
|
||||||
})
|
})
|
||||||
|
|
||||||
nodes := data.Nodes()
|
|
||||||
nodeCount := len(nodes)
|
|
||||||
sim := &Simulator{
|
sim := &Simulator{
|
||||||
data: data,
|
data: data,
|
||||||
network: network,
|
network: network,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Creating nodes...")
|
log.Println("Creating nodes...")
|
||||||
for i := 0; i < nodeCount; i++ {
|
for i := 0; i < data.NumNodes(); i++ {
|
||||||
node, err := sim.network.NewNodeWithConfig(nodeConfig(i))
|
node, err := sim.network.NewNodeWithConfig(nodeConfig(i))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("[ERROR] Can't start node: ", err)
|
log.Fatal("[ERROR] Can't start node: ", err)
|
||||||
|
@ -41,7 +41,7 @@ func TestAnalyze(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
stats := Analyze(plog, len(g.Nodes()), len(g.Links()))
|
stats := Analyze(plog, g.NumNodes(), g.NumLinks())
|
||||||
|
|
||||||
expected := []struct {
|
expected := []struct {
|
||||||
name string
|
name string
|
||||||
@ -77,9 +77,7 @@ func BenchmarkAnalyze(b *testing.B) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeCount := len(g.Nodes())
|
|
||||||
linksCount := len(g.Links())
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
Analyze(plog, nodeCount, linksCount)
|
Analyze(plog, g.NumNodes(), g.NumLinks())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user