绘制最长公共子序列问题的时间与输入大小的关系图

发布于 2024-10-03 23:23:04 字数 834 浏览 0 评论 0原文

我希望针对递归和动态编程方法中的最长常见子序列问题,绘制时间与输入大小的关系。到目前为止,我已经开发了以两种方式评估 lcs 函数的程序,一个简单的随机字符串生成器(在 此处)和 绘制图表的程序。现在我需要通过以下方式连接所有这些。

现在我必须连接所有这些。也就是说,计算 lcs 的两个程序应该运行大约 10 次,并将简单随机字符串生成器的输出作为这些程序的命令行参数给出。

计算执行这些程序所花费的时间,并将其与所使用的字符串长度一起存储在类似的文件中,

l=15, r=0.003, c=0.001 

由 python 程序解析以填充以下列表

sequence_lengths = [] 
recursive_times  = []
dynamic_times    = []

,然后绘制图表。关于上述问题我有以下问题。

1) 如何将一个 C 程序的输出作为命令行参数传递给另一个 C 程序?

2)是否有任何函数可以评估执行该函数所需的时间(以微秒为单位)?目前我唯一的选择是unix 中的时间函数。作为一个命令行实用程序使其更难以处理。

任何帮助将不胜感激。

I wish to plot the time against size of input, for Longest common subsequence problem in recursive as well as dynamic programming approaches. Until now I've developed programs for evaluating lcs functions in both ways, a simple random string generator(with help from here) and a program to plot the graph. Now I need to connect all these in the following way.

Now I have to connect all these. That is, the two programs for calculating lcs should run about 10 times with output from simple random string generator given as command line arguments to these programs.

The time taken for execution of these programs are calculated and this along with the length of strings used is stored in a file like

l=15, r=0.003, c=0.001 

This is parsed by the python program to populate the following lists

sequence_lengths = [] 
recursive_times  = []
dynamic_times    = []

and then the graph is plotted. I've the following questions regarding above.

1) How do I pass the output of one C program to another C program as command line arguments?

2) Is there any function to evaluate the time taken to execute the function in microseconds? Presently the only option I have is time function in unix. Being a command-line utility makes it tougher to handle.

Any help would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挽手叙旧 2024-10-10 23:23:04

如果程序之间传递的数据很小并且可以转换为字符格式,则可以将其作为一个或多个命令行参数传递。如果没有,您可以将其写入文件并将其名称作为参数传递。

对于 Python 程序,许多人使用 timeit 模块的 Timer 类来测量代码执行速度。您还可以使用 time 模块中的 clock()time() 函数进行滚动。分辨率取决于您运行的平台。

If the data being passed from program to program is small and can be converted to character format, you can pass it as one or more command-line arguments. If not you can write it to a file and pass its name as a argument.

For Python programs many people use the timeit module's Timer class to measure code execution speed. You can also roll-you-own using the clock() or time() functions in time module. The resolution depends on what platform you're running on.

放我走吧 2024-10-10 23:23:04

1)有很多方法,最简单的是使用 system 和从输出构造的字符串(或 popen 将其作为管道打开,如果您需要读回其输出),或者如果您希望离开当前程序,那么您可以使用各种 exec (将输出放在参数中)。

sh shell 中,您还可以使用 command2 $(command1 args_to_command_1) 执行此操作

2) 有关 C 语言的计时,请参阅 clockgetrusage

1) There are many ways, the simplest is to use system with a string constructed from the output (or popen to open it as a pipe if you need to read back its output), or if you wish to leave the current program then you can use the various exec (placing the output in the arguments).

In an sh shell you can also do this with command2 $(command1 args_to_command_1)

2) For timing in C, see clock and getrusage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文