Skip to content

Instantly share code, notes, and snippets.

@aniketp
Last active July 13, 2018 16:18
Show Gist options
  • Save aniketp/4e282f217c880dc7c01e9e65261b2374 to your computer and use it in GitHub Desktop.
Save aniketp/4e282f217c880dc7c01e9e65261b2374 to your computer and use it in GitHub Desktop.
A script for the performance benchmarking of CLIFF-CLAVIN tool. Developed for RTE-2018
import sys, csv, json, time, requests
from urllib.parse import urlencode, quote_plus
url = 'http://[SECRET]:8080/'
cliff_version = 'CLIFF-2.3.0'
malformed = 0
with open("data1.txt", "r") as file, open("hackcave2.csv", "w+") as csvf:
csvfile = csv.writer(csvf)
csvfile.writerow(['Index', 'Response time', 'Computation Time', 'Malformed'])
for index, line in enumerate(file):
malware = False
payload = {'q': line}
encoded_text = urlencode(payload, quote_via = quote_plus)
main_url = url + cliff_version + '/parse/text?' + encoded_text
start = time.time()
response = requests.get(main_url)
end = time.time()
try:
data = json.loads(response.text)
except:
print("malformed json")
malformed = malformed + 1
malware = True
timediff = str("%4.3f" % round(end - start, 3))
comptime = data["milliseconds"] / 1000
print("{index:3} - Response Time: {timediff} | Computation Time: {comptime:4.3f}".format(index = index + 1, timediff = timediff, \
comptime = comptime))
# Write to CSV
if malware:
csvfile.writerow([index + 1, timediff, comptime, "Malformed"])
else:
csvfile.writerow([index + 1, timediff, comptime])
file.close()
csvf.close()
print("\n" + str(malformed))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment