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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值