是否有可能获得postgres中的查询历史记录?是否有可能获得每个查询所花费的时间?我目前正在尝试在我正在处理的应用程序中识别慢查询.
我正在使用Postgres 8.3.5
我正在查看Web应用程序中的一些现有代码.我看到了这个:
window.setTimeout(function () { ... })
这是否只是立即执行功能内容?
在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.
我试着做一个测试,关于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) $ 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)
为什么用一个而不是另一个?
根据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?
怎样才能轻松地时间功能的药剂电话?
IEx中是否有任何隐藏的开关来启用此功能?
我正在尝试安排重复事件在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)
有什么其他方法可以做到这一点?
我有一个表上有一个插入触发器.如果我在存储过程的一个insert语句中将6000条记录插入到此表中,那么存储过程是否会在插入触发器完成之前返回?
只是为了确保我正确思考,触发器应该只被调用(我知道'被称为'不是正确的词),因为只有一个插入语句,对吧?
我的主要问题是:即使触发器没有完成,sproc会完成吗?
我想测量一个函数需要多长时间.
我有一个小问题:虽然我想要精确,并使用浮点,每次我使用%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
timing ×10
python ×3
performance ×2
arrays ×1
c ×1
class ×1
clock ×1
database ×1
delay ×1
dictionary ×1
elixir ×1
function ×1
java ×1
javascript ×1
linux ×1
list ×1
postgresql ×1
properties ×1
python-3.x ×1
settimeout ×1
sorting ×1
sql ×1
triggers ×1
ubuntu ×1