Created
January 20, 2016 12:51
-
-
Save alekseyl1992/71f0af8daaeb0e5fea00 to your computer and use it in GitHub Desktop.
Spark Perf test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def sample(p): | |
x, y = random.random(), random.random() | |
return 1 if x*x + y*y < 1 else 0 | |
def run(sc, num_samples): | |
count = sc.parallelize(xrange(0, num_samples)).map(sample) \ | |
.reduce(lambda a, b: a + b) | |
print "Pi is roughly %f" % (4.0 * count / num_samples) | |
def run_pure(num_samples): | |
count = reduce(lambda a, b: a + b, map(sample, xrange(0, num_samples))) | |
print "Pi is roughly %f" % (4.0 * count / num_samples) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment