示例#1
0
func main() {
	if debug.DEBUG {
		fmt.Printf("Loading config from speedtest.net\n")
	}
	sthttp.CONFIG = sthttp.GetConfig()

	if debug.DEBUG {
		fmt.Printf("Getting servers list...")
	}
	allServers := sthttp.GetServers()
	if debug.DEBUG {
		fmt.Printf("(%d) found\n", len(allServers))
	}

	closestServers := sthttp.GetClosestServers(NUMCLOSEST, allServers)

	fmt.Printf("Finding fastest server...")
	fastestServer := sthttp.GetFastestServer(NUMLATENCYTESTS, closestServers)
	fmt.Printf("%s (%s - %s)\n", fastestServer.Sponsor, fastestServer.Name, fastestServer.Country)

	dmbps := downloadTest(fastestServer)
	umbps := uploadTest(fastestServer)

	fmt.Printf("Ping: %s | Download: %3.2f Mbps | Upload: %3.2f Mbps\n", fastestServer.AvgLatency, dmbps, umbps)
}
示例#2
0
func main() {
	if debug.DEBUG {
		fmt.Printf("Loading config from speedtest.net\n")
	}
	sthttp.CONFIG = sthttp.GetConfig()

	if debug.DEBUG {
		fmt.Printf("Getting servers list...")
	}
	allServers := sthttp.GetServers()
	if debug.DEBUG {
		fmt.Printf("(%d) found\n", len(allServers))
	}

	if TESTSERVERID != "" {
		// they specified a server so find it in the list
		TESTSERVER = findServer(TESTSERVERID, allServers)
		fmt.Printf("(ID: %s) - %s (%s - %s) - %s\n", TESTSERVER.Id, TESTSERVER.Sponsor, TESTSERVER.Name, TESTSERVER.Country, TESTSERVER.Url)
		//FIXME: this is ugly, eventually we watn to get a true avg latency using NUMLATENCYTESTS
		fmt.Printf("Testing latency...\n")
		TESTSERVER.AvgLatency = sthttp.GetLatency(TESTSERVER)
	} else {
		// find a fast server for them
		closestServers := sthttp.GetClosestServers(NUMCLOSEST, allServers)
		fmt.Printf("Finding fastest server...")
		TESTSERVER = sthttp.GetFastestServer(NUMLATENCYTESTS, closestServers)
		fmt.Printf("(ID: %s) - %s (%s - %s) - %s\n", TESTSERVER.Id, TESTSERVER.Sponsor, TESTSERVER.Name, TESTSERVER.Country, TESTSERVER.Url)
	}

	dmbps := downloadTest(TESTSERVER)
	umbps := uploadTest(TESTSERVER)

	fmt.Printf("Ping: %s | Download: %3.2f Mbps | Upload: %3.2f Mbps\n", TESTSERVER.AvgLatency, dmbps, umbps)
}