zoukankan      html  css  js  c++  java
  • 初试线程-文件操作

    # -*- coding: utf-8 -*-
    import json
    import threading
    import time
    
    import requests
    from openpyxl import load_workbook
    
    
    file ="data_xiancheng.xlsx"
    
    
    def run_test():
        wb = load_workbook("data_xiancheng.xlsx")
        ws = wb.active
        for i in range(2,500):
    
            testValue = "".join(str(ws["A"+str(i)].value).split())
            refValue = "".join(str(ws["B"+str(i)].value).split())
    
            # print(testValue,refValue)
    
            url = "http://127.0.0.1:10013/antf/api/elasticSearch//compareFuzzyMatch/v1?testValue=" + testValue + "&refValue=" + refValue
            # print(url)
    
            headers = {"Content-Type": "application/json"}
            req = requests.get(url=url, headers=headers)
            res = json.loads(req.content)
    
    
            ws["C" + str(i)].value = res['responseBody']['insSimilarity']
            ws["D" + str(i)].value = res['responseBody']['antfSimilarity']
            ws["E" + str(i)].value = res['responseBody']['diffSimilarity']
    
        wb.save("data_xiancheng.xlsx")
    
    try:
        print('测试启动')
        start_time = time.time()
        t = threading.Thread(target=run_test) #创建线程  run_test是上面的函数
        t.start()   #启动线程
        t.join()   #主线程等待子线程执行结束
        end_time = time.time()
        print("耗时:",end_time-start_time)
    except Exception as e:
        print(e)

    测试50条数据:

    没用线程,56s

     

    用线程,3s


    一切技术都是为业务服务,脱离业务的技术一文不值!

  • 相关阅读:
    springboot+jsp 遇到的坑
    异步复位同步释放
    DDR工作原理(转载)
    FPGA基础 之逻辑单元
    二进制转BCD
    bcd转二进制
    FPGA学习笔记之IIC—EEPROM写和读
    FPGA学习笔记之mif文件生成方法总结
    FPGA_实验小项目:四位运算小计算器
    小小计算器之消零显示模块数码管消零
  • 原文地址:https://www.cnblogs.com/bubutianshu/p/11206707.html
Copyright © 2011-2022 走看看