<commit_before>#!/usr/bin/env python
import socket
import sys
import os
import timeit
import py9p

try:
    assert py9p.version > "1.0.6"
    from py9p import py9p
    assert hasattr(py9p, "Credentials")
    ng = True
except:
    ng = False

class CmdClient(py9p.Client):

    def cat(self, name, out=None):
        self.open(name)
        self.read(self.msize)
        self.close()

if __name__ == "__main__":

    if os.environ.has_key('USER'):
        user = os.environ['USER']

    sock = socket.socket(socket.AF_INET)
    try:
        sock.connect(('localhost', 10001),)
    except socket.error,e:
        print "%s" % ( e.args[1])
        sys.exit(255)

    if ng:
        cl = CmdClient(sock, py9p.Credentials(user), None)
    else:
        cl = CmdClient(py9p.Sock(sock, 0, 0), 'none', user, None, None, 0)

    t = timeit.Timer('cl.cat("sample1")','from __main__ import cl')
    print "1000 cats (walk/open/read/clunk) in", t.timeit(1000), "seconds"<commit_msg>test: allow profiling<commit_after>#!/usr/bin/env python
import socket
import sys
import os
import timeit
import py9p

try:
    assert py9p.version > "1.0.6"
    ng = py9p.version
    from py9p import py9p
    assert hasattr(py9p, "Credentials")
except:
    ng = False

class CmdClient(py9p.Client):

    def cat(self, name, out=None):
        self.open(name)
        self.read(self.msize)
        self.close()

if __name__ == "__main__":

    if os.environ.has_key('USER'):
        user = os.environ['USER']

    sock = socket.socket(socket.AF_INET)
    try:
        sock.connect(('localhost', 10001),)
    except socket.error,e:
        print "%s" % ( e.args[1])
        sys.exit(255)

    if ng:
        print "testing py9p.ng version %s" % (ng)
        cl = CmdClient(sock, py9p.Credentials(user), None)
    else:
        print "testing initial py9p"
        cl = CmdClient(py9p.Sock(sock, 0, 0), 'none', user, None, None, 0)

    if len(sys.argv) > 1 and sys.argv[1] == "profile":
        for x in range(1000):
            cl.cat("sample1")
    else:
        t = timeit.Timer('cl.cat("sample1")','from __main__ import cl')
        print "1000 cats (walk/open/read/clunk) in", t.timeit(1000), "seconds"
{'fraction_non_alphanumeric': 0.14705882352941177, 'fraction_numerical': 0.03400735294117647, 'mean_word_length': 2.634390651085142, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 6, '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': '5583673', 'n_tokens_mistral': 829, 'n_tokens_neox': 789, 'n_words': 189}