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秒,就不满足我的要求。

相关推荐
夏幻灵5 小时前
JavaScript this 面试:五种绑定规则、优先级与常见面试陷阱
开发语言·javascript·面试
程序猿编码5 小时前
榨干 RTX5090 算力!Qwen3 专用单卡推理引擎,手写C++/CUDA 算子实现 MTP 推测解码
开发语言·c++·大模型推理·qwen3·多模态推理
曹牧6 小时前
C#:未被引用的函数
c#
bkspiderx6 小时前
Qt 插件机制:动态扩展应用功能的核心框架
开发语言·qt·元数据·qt 插件·qpluginloader
程序员老陆7 小时前
深入理解 C++ thread_local:线程私有存储的正确打开方式
开发语言·c++·程序设计
沐晓时光7 小时前
C语言入门,深入理解指针(3)
c语言·开发语言
码云数智-园园7 小时前
unique_ptr 还是 shared_ptr?C++ 智能指针选型与内存泄漏实战分析
java·开发语言
禾小西8 小时前
07丨Redis 哨兵机制:主库故障后,如何恢复服务?
java·开发语言·redis
我不是阵雨8 小时前
JDK 21虚拟线程Pinning陷阱:一文拔钉解困
java·开发语言
全栈练习生8 小时前
AI Agent 沙箱
python·ai