测试我正在编程的程序
干草!
我想创建一个可以发现程序的复杂性(时间和空间)的测试。 功能按功能... 我想用库“time”来实现这一点,并在运行大量“n”的函数时计算秒数。
有人有更好的主意吗?也许它已经存在了? :)
谢谢! 阿米哈伊
Hay!
I would like to create a test that can find the complexity (time & space) of the program.
function by function...
I thought of doing so with the library "time" and to count seconds while running the functions for a large number of "n".
Does anyone have a better idea? maybe it already exists? :)
Thanks!
Amihay
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
至少对于时间复杂度来说,看起来是一个完全合理的方法。确保您的程序以有用的格式输出,例如 CSV 或制表符分隔,以便您可以轻松地将其复制/加载到电子表格中。
空间复杂度可能更难以可靠地获得。为此,您可能需要修改函数,以便它们返回有用的指标。例如,如果算法的主要数据结构是固定元素的映射,那么在运行期间返回映射的最大大小将为您提供足够的信息。
Looks like a perfectly reasonable approach, for the time complexity at least. Make sure that your program outputs in a useful format, for example CSV or tab separated, so that you can easily copy/load this into a spreadsheet.
Space complexity might be a bit more tricky to get reliably. For this, you might want to modify your functions so that they return a useful metric. For example, if the main data structure of your algorithm is a map of fixed elements, then returning the maximum size of the map during the run would give you enough information.
编写一些测试并进行性能分析。当然,您可以编写自己的函数,但这不是它的完成方式。好的分析器会为你提供你能想象到的各种信息。
请查看 msnd 上有关分析的此教程。
Write some tests and do performance profiling. Of course, you can write your own functions, but that is not the way how it is done. Good profiler will provide you with all kinds of information you can imagine.
Check out this tutorial on msnd about profiling.