Skip to content

Instantly share code, notes, and snippets.

@sh4869
Created June 6, 2015 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sh4869/9a35be4eab77b310eee5 to your computer and use it in GitHub Desktop.
Save sh4869/9a35be4eab77b310eee5 to your computer and use it in GitHub Desktop.

##コード

import 'package:benchmark_harness/benchmark_harness.dart';

// Create a new benchmark by extending BenchmarkBase.
class TemplateBenchmark extends BenchmarkBase {
	const TemplateBenchmark() : super("Template");

	static void main() {
		new TemplateBenchmark().report();
	}

	int fib(num n) {
		if (n < 2) return n;
		return fib(n - 2) + fib(n - 1);
	}
	// The benchmark code.
	void run() {
		print(fib(42));	
	}

	// Not measured: setup code executed before the benchmark runs.
	void setup() { }

	// Not measured: teardown code executed after the benchmark runs.
	void teardown() { }
}

// Main function runs the benchmark.
main() {
	// Run TemplateBenchmark.
	TemplateBenchmark.main();
}

Raspberry Piでの結果

267914296
267914296
267914296
267914296
267914296
267914296
267914296
267914296
267914296
267914296
267914296
Template(RunTime): 203695000.0 us.

##僕のマシン上

267914296
267914296
267914296
267914296
267914296
267914296
267914296
267914296
267914296
267914296
267914296
Template(RunTime): 69576000.0 us.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment