<commit_before>from time import clock
from random import *
from mpmath import *

w = """
def f(N):
    xs = []
    seed(1234)
    for i in range(N):
        x = mpf(random() * 2.0**randint(-10, 10)) ** 0.5
        y = mpf(random() * 2.0**randint(-10, 10)) ** 0.5
        x *= choice([1, -1])
        y *= choice([1, -1])
        xs.append((x, y))
    x, y = xs[0]
    OP
    t1 = clock()
    for x, y in xs:
        OP
    t2 = clock()
    return int(N/(t2-t1))

tests.append(("OP", f))
"""

tests = []
def deftest(op):
    exec w.replace("OP", op)

atests = ["x + y", "x - y", "x * y", "x / y", "x == y",
  "x < y", "abs(x)", "sqrt(abs(x))", "abs(x)**0.5",
  "exp(x)", "log(abs(x))", "x**42", "x**y",
  "sin(x)", "tan(x)", "atan(x)", "cosh(x)", "asin(x)",
  "gamma(x)", "erf(x)", "zeta(x)"]

for test in atests:
    deftest(test)

precs = [15, 30, 100, 500, 1000]

def runtests():
    print "\n    op / dps :",
    for prec in precs:
        print "%7s" % prec,
    print
    print "-" * 75
    for name, test in tests:
        print ("%12s" % name), ":",
        for prec in precs:
            mpf.dps = prec
            print "%7s" % test(max(50, 5000//prec)),
            mpf.dps = 15
        print

print "\nmpf timings (operations / second)"

#mpf.round_floor()
#import psyco
#psyco.full()

runtests()
<commit_msg>more benchmarks<commit_after>from time import clock
from random import *
from mpmath import *

w = """
def f(N):
    xs = []
    seed(1234)
    for i in range(N):
        x = mpf(random() * 2.0**randint(-10, 10)) ** 0.5
        y = mpf(random() * 2.0**randint(-10, 10)) ** 0.5
        x *= choice([1, -1])
        y *= choice([1, -1])
        xs.append((x, y))
    x, y = xs[0]
    OP
    t1 = clock()
    for x, y in xs:
        OP
    t2 = clock()
    return int(N/(t2-t1))

tests.append(("OP", f))
"""

tests = []
def deftest(op):
    exec w.replace("OP", op)

atests = ["int(x)", "float(x)", "str(x)", "+x", "-x",
  "x * 10", "x + 10", "x / 10",
  "x + y", "x - y", "x * y", "x / y", "x == y",
  "x < y", "abs(x)", "sqrt(abs(x))", "abs(x)**0.5",
  "exp(x)", "log(abs(x))", "x**42", "x**y",
  "sin(x)", "tan(x)", "atan(x)", "cosh(x)", "asin(x)",
  "gamma(x)", "erf(x)", "zeta(x)"]

for test in atests:
    deftest(test)

precs = [15, 30, 100, 500, 1000]

def runtests():
    print "\n    op / dps :",
    for prec in precs:
        print "%7s" % prec,
    print
    print "-" * 75
    for name, test in tests:
        print ("%12s" % name), ":",
        for prec in precs:
            mpf.dps = prec
            print "%7s" % test(max(50, 5000//prec)),
            mpf.dps = 15
        print

print "\nmpf timings (operations / second)"

#mpf.round_floor()
#import psyco
#psyco.full()

runtests()

{'fraction_non_alphanumeric': 0.22327707454289733, 'fraction_numerical': 0.0450070323488045, 'mean_word_length': 1.9209445585215605, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1413039', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1146, 'n_words': 306}