比较c中的两个函数 [英] compare two functions in c

查看:81
本文介绍了比较c中的两个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨......
我的应用程序中有2个函数,它们两者都在做相同的事情,但方式不同.现在我想保留其中的任何一个.所以可以请任何一个建议我如何从2个函数中找到合适的一个.是正确的),除非您有:

  1. A 目标(速度,较小的代码大小,鲁棒性,可移植性...)
  2. 一种确定(即衡量)哪种更合适的方法


除了CPallini所说的那样,如何将两者都保留在您的代码中?如果您有一个函数的两个实现,则可以编写一组测试,以比较您希望保留的结果与您将要舍弃的结果.

另一个标准(如果不需要优化,可能是最重要的标准)是函数的易读性.保持一个看起来像算法和沟渠的样子,就像遍地行走的蜘蛛一样.

干杯,


hi....
i have 2 functions in my application,both of them are doing the same thing but in different way. now i want to keep any one of them.so can any one please suggest me how to find the proper one out of the 2 functions

解决方案

Both of them (if correct) are ''the proper'' one, unless you have:

  1. A target (speed, smaller code size, robustness, portability,...)
  2. A method to determine (that is measure) which one better fits with the target.


In addition to what CPallini said how about keeping both in your code? If you have two implementations of a function you can write a set of tests that''ll compare the results of the one you want to keep with the one you''d have otherwise discarded.

Another criteria (and possibly the most important one if you don''t need to optimise) is how easy the functions are to read. Keep the one looks like the algorithm and ditch that looks like a spider''s walked all over it.

Cheers,

Ash


这篇关于比较c中的两个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆