python获取C#WEBAPI的数据

python代码

复制代码
import ast
import copy
import datetime
import json
import os
import random
import subprocess
import sys
import open3d as o3d;
import numpy as np
import pip;
import mmap

from multiprocessing import shared_memory

import requests
 
    
if __name__ == "__main__": 
    print("version")
    print(sys.path)
    print(o3d.__version__)
    print(sys.version)
    print(sys.executable)
    print(pip.__version__)
    print(pip.__file__)
    print(sys.getwindowsversion())

    
    try:
 

        try:
            print (f'开始测试 {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}')

            # 定义curl命令和参数
            curl_command = ['curl', '-X', 'GET', 'http://127.0.0.1:8200/Python/GetPlyDataV2']

            # 执行curl命令
            result = subprocess.run(curl_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            print(result.args) 
            print ('开始测试 1')
            #print(result.stderr) 
            print ('开始测试 2')
            #print(result.stdout) 
            print (f'开始测试 3 {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')}')
            data = json.loads(result.stdout.decode('utf-8'))
            print (f'开始测试 4 {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')}')
            print (f'开始测试 -----{len(data)}')
            #print(data)
 
        except Exception as e:
            print(f"请求异常: {e}")        


 
    except Exception as e:
        print(e)
    print('ok')

    print("version end")

C#代码

复制代码
      [HttpGet(Name = "GetPlyDataV2")]
      public ConcurrentQueue<ConcurrentQueue<double>> GetPlyDataV2()
      {
          Random random = new Random();
          int DataLength = 1001000;
          Stopwatch stopwatch = new Stopwatch();
          stopwatch.Start();
          // 或者预填充
          ConcurrentQueue<ConcurrentQueue<double>> Mylist2DFilled = new ConcurrentQueue<ConcurrentQueue<double>>();
          //Log.Logger.Debug($"开始添加数据 ");
          for (int row = 0; row < DataLength; row++)
          {
              ConcurrentQueue<double> rowList = new ConcurrentQueue<double>();
              for (int col = 0; col < 3; col++)
              {
                  rowList.Enqueue(random.NextDouble());
             }
              list2DFilled.Enqueue(rowList);
          }

          Log.Logger.Debug($"结束添加数据 ");
          stopwatch.Stop();
          Log.Logger.Debug($"ElapsedMilliseconds = [{stopwatch.ElapsedMilliseconds}]   ");
          return Mylist2DFilled; 

      }

python测试结果

想通过http传递大约8位数长度的二维数组给python,测试7位数以上耗时1秒多,但是8位数耗时就大大增大。目前超过1秒,就不满足我的要求。

相关推荐
Ronin3051 天前
【Qt常用控件】容器类控件和布局管理器
开发语言·qt·常用控件·布局管理器·容器类控件
菜鸡儿齐1 天前
Unsafe方法学习
java·python·学习
老师好,我是刘同学1 天前
Python执行命令并保存输出到文件
python
啵啵鱼爱吃小猫咪1 天前
机械臂阻抗控制github项目-mujoco仿真
开发语言·人工智能·python·机器人
似水明俊德1 天前
02-C#
开发语言·c#
MaximusCoder1 天前
等保测评命令——Centos Linux
linux·运维·经验分享·python·安全·centos
yunyun321231 天前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
m0_662577971 天前
高级爬虫技巧:处理JavaScript渲染(Selenium)
jvm·数据库·python
oem1101 天前
C++中的享元模式实战
开发语言·c++·算法
songyuc1 天前
【PyTorch】感觉`CrossEntropyLoss`和`BCELoss`很类似,为什么它们接收labels的shape常常不一样呢?
人工智能·pytorch·python