C++ 从.txt文件中提取信息的最佳方法

C++ 从.txt文件中提取信息的最佳方法,c++,regex,text,benchmarking,C++,Regex,Text,Benchmarking,我目前正在测试一些C++代码。遗憾的是,基准工具只向终端打印一个字符串(我必须使用这个基准工具,所以请不要推荐新的) 其中的一行如下所示: name, time, cycle, instr, L1-miss, LLC-miss, br-miss, task, scale, IPC, CPU, GHz Blitz2D, 0.00, 198423.00, 439478.00, 615.00, 3.00, 958.00, 39157.00, 1, 2

我目前正在测试一些C++代码。遗憾的是,基准工具只向终端打印一个字符串(我必须使用这个基准工具,所以请不要推荐新的)

其中的一行如下所示:

name, time,     cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Blitz2D, 0.00, 198423.00, 439478.00,  615.00,     3.00,  958.00, 39157.00,     1, 2.21, 1.14, 5.07
我现在做的是:
/a.out>some.txt

每个新的测试都有自己的新行,每个独立的测试块(基本上是相同的测试,但测试参数有所改变)由我选择的特殊字符分隔

从该文件中获取某些信息的最佳方式是什么? 最好是,某种数组,第二行中的每个数字都作为一个索引

我该怎么做?请记住,我对python、bash、regex等几乎一无所知(我愿意听取建议,并将尝试学习推荐的内容,但我不想为了找到最佳工作方式而必须学习多个。)

编辑: 最后,我需要这些信息在不同类型的图形图中。。。所以任何最适合的格式都是完美的

这是一个完整的测试块:

§
Testing with MxK * KxM Matrices - M: 29 - K: 67
    name, time,    cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Fastor2D, 0.00, 77568.00, 140312.00,  780.00,   206.00,  161.00, 15781.00,     1, 1.81, 1.45, 4.92 
    name, time,    cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Fastor2D, 0.00, 76681.00, 140312.00,  802.00,    39.00,  130.00, 15571.00,     1, 1.83, 1.44, 4.92 
    name, time,    cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Fastor2D, 0.00, 77174.00, 140312.00,  788.00,    31.00,  135.00, 15718.00,     1, 1.82, 1.45, 4.91 
    name, time,    cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Fastor2D, 0.00, 76720.00, 140312.00,  781.00,    30.00,  134.00, 15616.00,     1, 1.83, 1.44, 4.91 
    name, time,    cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Fastor2D, 0.00, 77052.00, 140312.00,  781.00,    16.00,  127.00, 15526.00,     1, 1.82, 1.43, 4.96 

   name, time,      cycle,      instr,   L1-miss, LLC-miss, br-miss,      task, scale,  IPC,  CPU,  GHz 
Eigen2D, 0.00, 3507208.00, 2477793.00, 129053.00,   999.00,  898.00, 724590.00,     1, 0.71, 1.01, 4.84 
   name, time,      cycle,      instr,   L1-miss, LLC-miss, br-miss,      task, scale,  IPC,  CPU,  GHz 
Eigen2D, 0.00, 3554544.00, 2477793.00, 128932.00,    37.00,  787.00, 734337.00,     1, 0.70, 1.01, 4.84 
   name, time,      cycle,      instr,   L1-miss, LLC-miss, br-miss,      task, scale,  IPC,  CPU,  GHz 
Eigen2D, 0.00, 3517898.00, 2477793.00, 128931.00,    25.00,  734.00, 726840.00,     1, 0.70, 1.01, 4.84 
   name, time,      cycle,      instr,   L1-miss, LLC-miss, br-miss,      task, scale,  IPC,  CPU,  GHz 
Eigen2D, 0.00, 3537674.00, 2483174.00, 129548.00,   683.00,  761.00, 730925.00,     1, 0.70, 1.01, 4.84 
   name, time,      cycle,      instr,   L1-miss, LLC-miss, br-miss,      task, scale,  IPC,  CPU,  GHz 
Eigen2D, 0.00, 3527303.00, 2481152.00, 129326.00,   190.00,  741.00, 728567.00,     1, 0.70, 1.01, 4.84 

     name, time,    cycle,    instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
XTensor2D, 0.00, 60718.00, 78733.00, 3363.00,   434.00,  206.00, 12772.00,     1, 1.30, 1.72, 4.75 
     name, time,    cycle,    instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
XTensor2D, 0.00, 56300.00, 78733.00, 3335.00,    32.00,  146.00, 11445.00,     1, 1.40, 1.79, 4.92 
     name, time,    cycle,    instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
XTensor2D, 0.00, 55279.00, 78733.00, 3340.00,    39.00,  121.00, 11305.00,     1, 1.42, 1.79, 4.89 
     name, time,    cycle,    instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
XTensor2D, 0.00, 55294.00, 78733.00, 3344.00,    22.00,  114.00, 11297.00,     1, 1.42, 1.79, 4.89 
     name, time,    cycle,    instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
XTensor2D, 0.00, 54857.00, 78733.00, 3322.00,     6.00,  108.00, 11233.00,     1, 1.44, 1.80, 4.88 

   name, time,     cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Blitz2D, 0.00, 198423.00, 439478.00,  615.00,     3.00,  958.00, 39157.00,     1, 2.21, 1.14, 5.07 
   name, time,     cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Blitz2D, 0.00, 190556.00, 439478.00,  584.00,     2.00,  964.00, 39058.00,     1, 2.31, 1.14, 4.88 
   name, time,     cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Blitz2D, 0.00, 190088.00, 439478.00,  581.00,     8.00,  948.00, 39057.00,     1, 2.31, 1.14, 4.87 
   name, time,     cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Blitz2D, 0.00, 190177.00, 439478.00,  594.00,    11.00,  941.00, 38989.00,     1, 2.31, 1.14, 4.88 
   name, time,     cycle,     instr, L1-miss, LLC-miss, br-miss,     task, scale,  IPC,  CPU,  GHz 
Blitz2D, 0.00, 190099.00, 439478.00,  584.00,     7.00,  943.00, 39030.00,     1, 2.31, 1.14, 4.87 

     name, time,    cycle,    instr, L1-miss, LLC-miss, br-miss,    task, scale,  IPC,   CPU,  GHz 
FTensor2D, 0.00, 24970.00, 17695.00,   96.00,    19.00,  101.00, 4851.00,     1, 0.71, 29.76, 5.15 
     name, time,    cycle,    instr, L1-miss, LLC-miss, br-miss,    task, scale,  IPC,   CPU,  GHz 
FTensor2D, 0.00, 24619.00, 17695.00,   85.00,     8.00,   94.00, 4738.00,     1, 0.72, 48.35, 5.20 
     name, time,    cycle,    instr, L1-miss, LLC-miss, br-miss,    task, scale,  IPC,   CPU,  GHz 
FTensor2D, 0.00, 24471.00, 17695.00,   68.00,     2.00,   94.00, 4739.00,     1, 0.72, 48.36, 5.16 
     name, time,    cycle,    instr, L1-miss, LLC-miss, br-miss,    task, scale,  IPC,   CPU,  GHz 
FTensor2D, 0.00, 24454.00, 17695.00,   74.00,     4.00,   93.00, 4727.00,     1, 0.72, 43.77, 5.17 
     name, time,    cycle,    instr, L1-miss, LLC-miss, br-miss,    task, scale,  IPC,   CPU,  GHz 
FTensor2D, 0.00, 24318.00, 17695.00,   83.00,    16.00,   93.00, 4703.00,     1, 0.73, 54.69, 5.17 
§

通过编辑,您可以grep“2D”>data.txt以仅获取数据,然后在Calc中打开该数据。2D位于您的所有姓名列中,因此它将是一个易于使用的字符串

# run benchmarking
./a.out > some.txt
# Extract data from some.txt
grep "2D" some.txt > data.csv
# Open with libreoffice calc and plot
libreoffice data.csv

或者,您可以使用命令行绘图工具(比如gnuplot)来绘制data.txt。您还可以更具体地使用grep命令来仅提取特定数据

通过编辑,您可以grep“2D”>data.txt以仅获取数据,然后在Calc中打开该数据。2D位于您的所有姓名列中,因此它将是一个易于使用的字符串

# run benchmarking
./a.out > some.txt
# Extract data from some.txt
grep "2D" some.txt > data.csv
# Open with libreoffice calc and plot
libreoffice data.csv

或者,您可以使用命令行绘图工具(比如gnuplot)来绘制data.txt。您还可以更具体地使用grep命令来仅提取特定数据

这真的取决于你想用这些信息做什么。。。您的输出是CSV格式的,即使您将其写入文本文件。Excel/LibreOffice Calc可以将此文件打开到电子表格中,没有问题。如果您只想打印一列,bash工具可能会很好。如果需要将整个文件作为数据数组读入,python的numpy或pandas可能是一个很好的工具。同样,这取决于你想对你的数据做什么。实际上LibreOffice的想法听起来不错,因为我想从这些信息中创建图形图。我会调查的。事先有什么建议和警告吗?没有。使用导入工具并确保它正确地分离数据。。。e、 g.当固定宽度格式明显以逗号分隔时,不要使用固定宽度格式。使用Calc进行新编辑时,您必须删除“名称、时间,…”每次导入行时,手动创建行。或者,您可以进行一些搜索来删除它们(例如使用bash的字符串编辑器工具sed)。如何制定工作流程取决于您。理想情况下,您可以编写脚本。如果你不想使用Calc,gnuplot将是一个很好的绘图工具,但它可能比学习它更麻烦。它实际上取决于你想用这些信息做什么。。。您的输出是CSV格式的,即使您将其写入文本文件。Excel/LibreOffice Calc可以将此文件打开到电子表格中,没有问题。如果您只想打印一列,bash工具可能会很好。如果需要将整个文件作为数据数组读入,python的numpy或pandas可能是一个很好的工具。同样,这取决于你想对你的数据做什么。实际上LibreOffice的想法听起来不错,因为我想从这些信息中创建图形图。我会调查的。事先有什么建议和警告吗?没有。使用导入工具并确保它正确地分离数据。。。e、 g.当固定宽度格式明显以逗号分隔时,不要使用固定宽度格式。使用Calc进行新编辑时,您必须删除“名称、时间,…”每次导入行时,手动创建行。或者,您可以进行一些搜索来删除它们(例如使用bash的字符串编辑器工具sed)。如何制定工作流程取决于您。理想情况下,您可以编写脚本。如果你不想使用Calc,gnuplot将是一个很好的绘图工具,但它可能比学习它更麻烦。我会试试,非常感谢,当我得到一些结果时我会再写一次。它起作用了,但现在我必须看看如何在LibreOffice中实现每5行的平均值。我会试试,非常感谢,当我得到一些结果时,我会再写一次。它起作用了,但现在我必须看看如何在LibreOffice中计算每5行的平均值