<commit_before>import random
import subprocess
import time

TEST_TIME = 10

proc = subprocess.Popen(['./disorderCook.exe', "SELLEX", "CATS"], shell = False, stdin = subprocess.PIPE, stdout = subprocess.PIPE)

def get_response_from_process(proc, message):       # MUST MATCH THE REAL THING IN THE FRONTEND, ELSE DEADLOCK
    assert(isinstance(message, str))

    if not message.endswith("\n"):
        message += "\n"
    
    b_message = bytes(message, encoding = "ascii")
    
    proc.stdin.write(b_message)
    proc.stdin.flush()
    
    result = ""
    
    while 1:
        line = str(proc.stdout.readline(), encoding = "ascii")
        if line.strip() == ("END"):         # line ending with \r\n has been observed to happen
            return result
        else:
            result += line

# ----------------------------------------------------------------------

print("Placing many orders...")
all_account_ids = dict()
starttime = time.clock()
n = 0
while 1:
    # print(n)
    n += 1
    price = random.randint(1, 5000)
    qty = random.randint(1, 100)
    direction = random.choice([1, 2])
    orderType = random.choice([1, 1, 1, 1, 2, 3, 4])

    account = "account" + str(n // 1000)
    if account not in all_account_ids:
        all_account_ids[account] = len(all_account_ids)
    acc_id = all_account_ids[account]
    
    message = "ORDER {} {} {} {} {} {}".format(account, acc_id, qty, price, direction, orderType)
    raw_response = get_response_from_process(proc, message)
    # print(raw_response)
    
    # time.sleep(0.01)
    if time.clock() - starttime > TEST_TIME:
        break

print("{} orders placed in {} seconds".format(n, TEST_TIME))
print("= {} per second".format(n // TEST_TIME))

debug_info = get_response_from_process(proc, "__DEBUG_MEMORY__")
print(debug_info)


print("Getting many quotes...")
starttime = time.clock()
n = 0
while 1:
    n += 1
    raw_response = get_response_from_process(proc, "QUOTE")
    # print(raw_response)
    
    # time.sleep(0.01)
    if time.clock() - starttime > TEST_TIME:
        break

print("{} quotes received in {} seconds".format(n, TEST_TIME))
print("= {} per second".format(n // TEST_TIME))

input()
<commit_msg>add book-getting to test<commit_after>import random
import subprocess
import time

TEST_TIME = 10

proc = subprocess.Popen(['./disorderCook.exe', "SELLEX", "CATS"], shell = False, stdin = subprocess.PIPE, stdout = subprocess.PIPE)

def get_response_from_process(proc, message):       # MUST MATCH THE REAL THING IN THE FRONTEND, ELSE DEADLOCK
    assert(isinstance(message, str))

    if not message.endswith("\n"):
        message += "\n"
    
    b_message = bytes(message, encoding = "ascii")
    
    proc.stdin.write(b_message)
    proc.stdin.flush()
    
    result = ""
    
    while 1:
        line = str(proc.stdout.readline(), encoding = "ascii")
        if line.strip() == ("END"):         # line ending with \r\n has been observed to happen
            return result
        else:
            result += line

# ----------------------------------------------------------------------

print("Placing many orders...")
all_account_ids = dict()
starttime = time.clock()
n = 0
while 1:
    # print(n)
    n += 1
    price = random.randint(1, 5000)
    qty = random.randint(1, 100)
    direction = random.choice([1, 2])
    orderType = random.choice([1, 1, 1, 1, 2, 3, 4])

    account = "account" + str(n // 1000)
    if account not in all_account_ids:
        all_account_ids[account] = len(all_account_ids)
    acc_id = all_account_ids[account]
    
    message = "ORDER {} {} {} {} {} {}".format(account, acc_id, qty, price, direction, orderType)
    raw_response = get_response_from_process(proc, message)
    # print(raw_response)
    
    # time.sleep(0.01)
    if time.clock() - starttime > TEST_TIME:
        break

print("{} orders placed in {} seconds".format(n, TEST_TIME))
print("= {} per second".format(n // TEST_TIME))

debug_info = get_response_from_process(proc, "__DEBUG_MEMORY__")
print(debug_info)


print("Getting many quotes...")
starttime = time.clock()
n = 0
while 1:
    n += 1
    raw_response = get_response_from_process(proc, "QUOTE")
    # print(raw_response)
    
    # time.sleep(0.01)
    if time.clock() - starttime > TEST_TIME:
        break

print("{} quotes received in {} seconds".format(n, TEST_TIME))
print("= {} per second\n".format(n // TEST_TIME))

print("Getting many books...")
starttime = time.clock()
n = 0
while 1:
    n += 1
    raw_response = get_response_from_process(proc, "ORDERBOOK")
    # print(raw_response)
    
    # time.sleep(0.01)
    if time.clock() - starttime > TEST_TIME:
        break

print("{} books received in {} seconds".format(n, TEST_TIME))
print("= {} per second".format(n // TEST_TIME))

input()

{'fraction_non_alphanumeric': 0.16799496644295303, 'fraction_numerical': 0.016778523489932886, 'mean_word_length': 2.6883217324052593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '6049989', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1545, 'n_words': 386}