aboutsummaryrefslogtreecommitdiffstats
path: root/simulation/utils.go
diff options
context:
space:
mode:
authorhaoping-ku <haoping.ku@dexon.org>2018-12-05 17:38:03 +0800
committerGitHub <noreply@github.com>2018-12-05 17:38:03 +0800
commit4eb02f1dd96e136b0f7cf7eff792da1e44176713 (patch)
tree3757739bff31ce4b9cb7ff45be572f9858fc19e9 /simulation/utils.go
parent1f48b590f6e9a6d3fd773846a3d8ba1b7f0419e6 (diff)
downloaddexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar
dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar.gz
dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar.bz2
dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar.lz
dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar.xz
dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.tar.zst
dexon-consensus-4eb02f1dd96e136b0f7cf7eff792da1e44176713.zip
Haoping fix simulation (#356)
* simulation: add benchmark features * tmp * simulation: modify Debug interface * Added BlockReceived and BlockReady function to Debug interface. * Added Benchmark features. * fix * fix typos
Diffstat (limited to 'simulation/utils.go')
-rw-r--r--simulation/utils.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/simulation/utils.go b/simulation/utils.go
new file mode 100644
index 0000000..f0d864b
--- /dev/null
+++ b/simulation/utils.go
@@ -0,0 +1,36 @@
+// Copyright 2018 The dexon-consensus Authors
+// This file is part of the dexon-consensus library.
+//
+// The dexon-consensus library is free software: you can redistribute it
+// and/or modify it under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation, either version 3 of the License,
+// or (at your option) any later version.
+//
+// The dexon-consensus library is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
+// General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the dexon-consensus library. If not, see
+// <http://www.gnu.org/licenses/>.
+
+package simulation
+
+import (
+ "math"
+)
+
+func calcMeanAndStdDeviation(a []float64) (float64, float64) {
+ sum := float64(0)
+ for _, i := range a {
+ sum += i
+ }
+ mean := sum / float64(len(a))
+ dev := float64(0)
+ for _, i := range a {
+ dev += (i - mean) * (i - mean)
+ }
+ dev = math.Sqrt(dev / float64(len(a)))
+ return mean, dev
+}