PHP中的函数调用很昂贵.这是一个测试它的小基准:
<?php
const RUNS = 1000000;
// create test string
$string = str_repeat('a', 1000);
$maxChars = 500;
// with function call
$start = microtime(true);
for ($i = 0; $i < RUNS; ++$i) {
strlen($string) <= $maxChars;
}
echo 'with function call: ', microtime(true) - $start, "\n";
// without function call
$start = microtime(true);
for ($i = 0; $i < RUNS; ++$i) {
!isset($string[$maxChars]);
}
echo 'without function call: ', microtime(true) - $start;
Run Code Online (Sandbox Code Playgroud)
这使用函数first(strlen)测试功能相同的代码,然后不使用函数(isset不是函数).
我得到以下输出:
with function …Run Code Online (Sandbox Code Playgroud) 我正在使用Node.js:
var s = 'Who\'s that girl?';
var url = 'http://graph.facebook.com/?text=' + encodeURIComponent(s);
request(url, POST, ...)
Run Code Online (Sandbox Code Playgroud)
这不起作用!Facebook切断了我的文字......
完整代码:
function postToFacebook(fbid, access_token, data, next){
var uri = 'https://graph.facebook.com/'+String(fbid)+'/feed?access_token='+access_token;
var uri += '&' + querystring.stringify(data);
request({
'method':'POST',
'uri': uri,
},function(err,response,body){
next();
});
};
app.get('/test',function(req,res){
var d = {
'name':'Who\'s that girl?',
'link': 'http://example.com',
'caption': 'some caption...',
'description': 'some description...',
'picture': 'http://i.imgur.com/CmlrM.png',
};
postToFacebook(req.user.fb.id, req.user.fb.accessToken, d);
res.send('done');
});
Run Code Online (Sandbox Code Playgroud)
Facebook在墙上发布了一个空白帖子.没有文字显示.没有.
当我记录我的URI时,它是这样的:
https://graph.facebook.com/1290502368/feed?access_token=2067022539347370|d7ae6f314515c918732eab36.1-1230602668|GtOJ-pi3ZBatd41tPvrHb0OIYyk&name=Who's%20that%20girl%3F&link=http%3A%2F%2Fexample.com&caption=some%20caption...&description=some%20description...&picture=http%3A%2F%2Fi.imgur.com%2FCmlrM.png
Run Code Online (Sandbox Code Playgroud)
显然,如果您查看该URL,您会看到撇号未正确编码.
Python的内置函数int是否仍尝试转换提交的值,即使该值已经是整数?
更简洁:是否有任何之间的性能差异int('42'),并int(42)通过转换算法造成的?
我在Stack Overflow上发现了很多关于这个问题的问题,但是他们都对某些部分非常具体.我确实找到了这个问题,其答案提供了一些很好的参考,但它们并没有真正解释它是如何工作的,它们的例子几乎没有做任何事情.我想更多地了解它是如何一起工作的,我想使用vanilla JavaScript.
(此外,其他问题的许多答案都已有数年之久了.)
我在网上看到的大多数代码都使用document.onkeydown,但MDN只列出window.onkeydown.此评论还建议使用window.onkeydown.是否存在使用其中一个的差异或理由?
ffmpeg的有一个-quality带有选项编码VP9时设置best,good和realtime.如何将这些选项会影响其他可用的编码选项(例如,-speed,-slices,-frame-parallel,等...)?我在某个地方阅读-best并且-good -speed 0会给出相同的质量,后者要快得多.对我来说,这听起来像质量设置只是更改其他选项(如-speed),就好像它们只是预设,人们可以手动获得相同的结果.这是真的,还是质量设置会影响我无法通过其他选项更改的内容?
我正在使用的网页包含按字母顺序排序的div列表,这些div都具有相同的类.如果我调用document.getElementsByClassName('classname'),我可以确定它返回的数组将按HTML顺序排序吗?
如果我从 void 函数返回一个 void 函数,在返回之前会调用该函数吗?
例子:
#include <iostream>
void one ( ) { std::cout << "Hello world.\n"; }
void two ( ) { return one ( ); }
int main ( ) { two ( ); }
Run Code Online (Sandbox Code Playgroud)
将“Hello world”。打印到屏幕上?