【发布时间】:2021-08-28 03:38:32
【问题描述】:
在 python 和 c++ 中读取相同的羽毛文件时,在 python 中,函数 pyarrow.feather.read_table() 表现得比我用于 c++ 的 API 好。当我进一步调查时,我发现主要区别是因为在 python 中 read_table() API 使用了一个名为 memory_map 的标志(默认设置为 true)。当我禁用此标志时,c++ API 的性能比 python 中的 read_table() 更好。现在正如它所暗示的那样,c++ 默认情况下不使用 memory_mapping,而是为了提高我想使用它的性能。请建议我为 c++ i 使用内存映射的方法,因为在可用于 c++ 的文档中没有找到任何感兴趣的 API。 我正在使用的代码是 -
#!/usr/bin/env python3
import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq
import pyarrow.feather
import time
for i in range(20):
start_time = time.time()
table = pyarrow.feather.read_table('data'+str(i + 1)+'.feather')
end_time = time.time()
print("Time taken to read file is : ",(end_time - start_time)*1000,"ms")
C++ 代码是 -
void read_feather_to_table(std::string path,std::shared_ptr<arrow::Table> *feather_table){
std::shared_ptr <arrow::io::RandomAccessFile> input_file = file_system.OpenInputFile(path).ValueOrDie();
std::shared_ptr <arrow::ipc::feather::Reader> feather_reader = arrow::ipc::feather::Reader::Open(input_file).ValueOrDie();
auto t1 = std::chrono::high_resolution_clock::now();
arrow::Status temp_status = feather_reader -> Read(feather_table);
auto t2 = std::chrono::high_resolution_clock::now();
auto ms_int = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
std::cout << "Time taken to read file is : "<< ms_int.count()<< "ms\n";
return;
}
【问题讨论】:
标签: python c++ pyarrow apache-arrow feather