标签: timing

是否有可能获得postgres中的查询历史记录

是否有可能获得postgres中的查询历史记录?是否有可能获得每个查询所花费的时间?我目前正在尝试在我正在处理的应用程序中识别慢查询.

我正在使用Postgres 8.3.5

database postgresql performance timing

53
推荐指数
2
解决办法
8万
查看次数

setTimeout没有延迟和立即执行函数一样吗?

我正在查看Web应用程序中的一些现有代码.我看到了这个:

window.setTimeout(function () { ... })

这是否只是立即执行功能内容?

javascript timing delay settimeout

50
推荐指数
2
解决办法
2万
查看次数

Python类@property:使用setter但是避开getter?

在python类中,@ property是一个很好的装饰器,可以避免使用显式的setter和getter函数.然而,它的成本是"经典"类功能的2-5倍.在我的情况下,在设置属性的情况下这是非常好的,与设置时需要完成的处理相比,开销是微不足道的.

但是,在获得房产时我不需要处理.它总是只是"回归自我.属性".是否有一种优雅的方式来使用setter但不使用getter,而不需要使用不同的内部变量?

为了说明,下面的类具有属性"var",它指的是内部变量"_var".它需要更长的时间称为"VAR"比"_var"但它会是很好,如果开发者和用户都可以只使用"无功",而无需守得的"_var"的轨道.

class MyClass(object):
  def __init__(self):
    self._var = None

  # the property "var". First the getter, then the setter
  @property
  def var(self):
    return self._var
  @var.setter
  def var(self, newValue):
    self._var = newValue
    #... and a lot of other stuff here

  # Use "var" a lot! How to avoid the overhead of the getter and not to call self._var!
  def useAttribute(self):
    for i in xrange(100000):
      self.var == 'something'
Run Code Online (Sandbox Code Playgroud)

对于那些感兴趣的人,在我的电脑上调用"var"平均需要204 ns,而调用"_var"平均需要44 ns.

python properties class timing

49
推荐指数
3
解决办法
2万
查看次数

为什么Collections.sort()比Arrays.sort()慢得多?

我试着做一个测试,关于Collection.sort()Arrays.sort().在测试中,我创建了一个int长度为1e5100 的s 数组,其中包含从1到1e5的随机数.我还创建了一个类型列表Integer,它在与数组相同的位置包含相同的值.然后我使用Arrays.sort()和列表使用排序数组Collections.sort().


更新:正如@Holger指出的那样,我的代码有一个错误.修正后的代码现在是:

import java.util.* ;


class TestClass {
    public static void main(String args[] ) throws Exception {
        double ratSum = 0 ;
        for(int j=0;j<100;j++)
        {
        int[] A = new int[(int)1e5] ;
        List<Integer> L = new ArrayList<Integer>() ;
        for(int i=0;i<A.length;i++)
        {
            int no = (int)(Math.random()*(int)1e5) ;
            A[i] = no ;
            L.add(A[i]) ;
        }

        long startTime = System.nanoTime() ;
        Arrays.sort(A) ;
        long endTime = System.nanoTime() …
Run Code Online (Sandbox Code Playgroud)

java arrays sorting list timing

48
推荐指数
2
解决办法
6379
查看次数

"d = dict()"和"d = {}"之间的差异

$ python2.7 -m timeit 'd={}'
10000000 loops, best of 3: 0.0331 usec per loop
$ python2.7 -m timeit 'd=dict()'
1000000 loops, best of 3: 0.19 usec per loop
Run Code Online (Sandbox Code Playgroud)

为什么用一个而不是另一个?

python performance dictionary timing

35
推荐指数
4
解决办法
2万
查看次数

CLOCK_MONOTONIC和CLOCK_MONOTONIC_RAW有什么区别?

根据Ubuntu下的Linux手册页

CLOCK_MONOTONIC
      Clock that cannot be set and  represents  monotonic  time  since
      some unspecified starting point.

CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)
      Similar  to  CLOCK_MONOTONIC, but provides access to a raw hard?
      ware-based time that is not subject to NTP adjustments.
Run Code Online (Sandbox Code Playgroud)

根据韦伯斯特在线词典Monotonic的意思是:

2:随着独立变量的值或术语的下标的增加,具有永不增加或永不减少的属性.

换句话说,它不会向后跳.我可以看到,如果你计算一些代码,这将是一个重要的属性.

但是,正常版本和原始版本之间的差异尚不清楚.有人可以了解一下NTP如何影响CLOCK_MONOTONIC?

linux ubuntu timing

35
推荐指数
1
解决办法
3万
查看次数

我们如何轻松地在灵药中调用函数调用?

怎样才能轻松地时间功能的药剂电话?

IEx中是否有任何隐藏的开关来启用此功能?

function timing elixir

30
推荐指数
2
解决办法
1万
查看次数

在Python 3中安排重复事件

我正在尝试安排重复事件在Python 3中每分钟运行一次.

我见过上课,sched.scheduler但我想知道是否还有其他方法可以做到.我听说提到我可以使用多个线程,我不介意这样做.

我基本上要求一些JSON,然后解析它; 它的价值随着时间而变化.

要使用sched.scheduler我必须创建一个循环来请求它安排甚至运行一小时:

scheduler = sched.scheduler(time.time, time.sleep)

# Schedule the event. THIS IS UGLY!
for i in range(60):
    scheduler.enter(3600 * i, 1, query_rate_limit, ())

scheduler.run()
Run Code Online (Sandbox Code Playgroud)

有什么其他方法可以做到这一点?

python timing scheduled-tasks python-3.x

29
推荐指数
7
解决办法
7万
查看次数

Sql触发器是同步还是异步?

我有一个表上有一个插入触发器.如果我在存储过程的一个insert语句中将6000条记录插入到此表中,那么存储过程是否会在插入触发器完成之前返回?

只是为了确保我正确思考,触发器应该只被调用(我知道'被称为'不是正确的词),因为只有一个插入语句,对吧?

我的主要问题是:即使触发器没有完成,sproc会完成吗?

sql triggers stored-procedures timing

27
推荐指数
2
解决办法
1万
查看次数

测量函数所花费的时间:clock_gettime

我想测量一个函数需要多长时间.

我有一个小问题:虽然我想要精确,并使用浮点,每次我使用%lf打印我的代码我得到两个答案之一:1.000 ...或0.000 ....这让我想知道如果我的代码是正确的:

#define BILLION  1000000000L;

// Calculate time taken by a request
struct timespec requestStart, requestEnd;
clock_gettime(CLOCK_REALTIME, &requestStart);
function_call();
clock_gettime(CLOCK_REALTIME, &requestEnd);

// Calculate time it took
double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
  + ( requestEnd.tv_nsec - requestStart.tv_nsec )
  / BILLION;
printf( "%lf\n", accum );
Run Code Online (Sandbox Code Playgroud)

大部分代码都不是由我做的.此示例页面包含说明clock_gettime使用的代码:http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom/clibref/qnx/clock_gettime.html

任何人都可以让我知道什么是不正确的,或者为什么我只得到整数值?

非常感谢你,

Jary

c timing clock

27
推荐指数
2
解决办法
7万
查看次数