Ejemplo n.º 1
0
func main() {
	tests := []*Test{}
	// if file, err := os.Open("results.txt"); err != nil {
	if file, err := os.Stdin, error(nil); err != nil {
		log.Fatal(err)
	} else {
		scanner := bufio.NewScanner(file)
		for scanner.Scan() {
			test, err := ParseLine(scanner.Text())
			if err != nil {
				continue
			}
			test.Calculate()
			tests = append(tests, test)
		}
	}
	if len(tests) == 0 {
		log.Fatal("No tests found.")
	}
	if plt, err := plot.New(); err != nil {
		log.Fatal(err)
	} else {
		for i, test := range tests {
			xys := test.ToXY(100000.0)
			line, err := plotter.NewLine(xys)
			if err != nil {
				log.Fatal(err)
			}
			line.Color, line.Dashes = plotutil.Color(i), plotutil.Dashes(0)
			plt.Add(line)
			{
				name := fmt.Sprintf("%s (%d)", test.Name, int(test.Stats.Mean/100000))
				plt.Legend.Add(name, line)
			}
		}
		// plt.Legend.Font.Size = vg.Inches(plt.Legend.Font.Size * 0.75)
		plt.Legend.Font.Size *= 0.65
		plt.Legend.Top = true
		plt.Legend.Left = true
		// plt.Legend.YOffs = vg.Inches(-1.12)
		// plt.Legend.XOffs = vg.Inches(1)
		plt.HideX()
		// plt.X.Padding = 20
		plt.Y.Min = 0
		plt.Y.Max = 1600
		plt.Title.Text = fmt.Sprintf("Speed Test (averaged over %d runs and %d tests)", 100000, 100)
		plt.Y.Label.Text = "Cycles"
		plt.Save(6, 4, "number-parse.svg")
	}
}
Ejemplo n.º 2
0
func plotBehind(sp *raw.SpicePlot, scale_vector *raw.SpiceVector, typemap map[string][]*raw.SpiceVector) PlotMap {
	m := findMultiplicity(scale_vector.Data)
	c := int(sp.NPoints) / m
	plots := PlotMap{}
	for vector_type, vectors := range typemap {
		plot, err := plot.New()
		if err != nil {
			log.Fatal(err)
		}
		for i, vector := range vectors {
			xys := SpiceToXY(scale_vector, vector)
			for j := 0; j < m; j++ {
				line, err := plotter.NewLine(xys[j*c : (j+1)*c])
				if err != nil {
					log.Fatal(err)
				}
				line.Color = plotutil.Color(i)
				line.Dashes = plotutil.Dashes(0)
				plot.Add(line)
				// plot.Legend.Add(vector.Name, line)
				// plot.Legend.Add(fmt.Sprintf("%s-%d", vector.Name, j), line)
				if j == 0 {
					plot.Legend.Add(vector.Name, line)
				}
			}
			// xys := SpiceToXY(scale_vector, vector)
			// line, err := plotter.NewLine(xys)
			// if err != nil {
			// 	log.Fatal(err)
			// }
			// line.Color = plotutil.Color(i + 1)
			// line.Dashes = plotutil.Dashes(0)
			// plot.Add(line)
			// plot.Legend.Add(vector.Name, line)
		}
		plot.Title.Text = sp.Title + ": " + sp.Name
		plot.X.Label.Text = scale_vector.Name
		plot.Y.Label.Text = vector_type
		// plots = append(plots, plot)
		plots[vector_type] = plot
	}
	return plots
}
Ejemplo n.º 3
0
// Add colored line to chart
func InfoAddLinePoints(plt *plot.Plot, color int, vs ...interface{}) error {
	var ps []plot.Plotter
	names := make(map[[2]plot.Thumbnailer]string)
	name := ""
	var i int = color
	for _, v := range vs {
		switch t := v.(type) {
		case string:
			name = t

		case plotter.XYer:
			l, s, err := plotter.NewLinePoints(t)
			if err != nil {
				return err
			}
			l.Color = plotutil.Color(i)
			l.Dashes = plotutil.Dashes(i)
			s.Color = plotutil.Color(i)
			s.Shape = plotutil.Shape(i)
			i++
			ps = append(ps, l, s)
			if name != "" {
				names[[2]plot.Thumbnailer{l, s}] = name
				name = ""
			}

		default:
			panic(fmt.Sprintf("AddLinePoints handles strings and plotter.XYers, got %T", t))
		}
	}
	plt.Add(ps...)
	for ps, n := range names {
		plt.Legend.Add(n, ps[0], ps[1])
	}
	return nil
}