(相关:如何在Sandy Bridge上的一系列int中快速将位计数到单独的bin中?是对此的早期复制,带有一些不同的答案。编者注:这里的答案可能更好。
同样,是类似问题的AVX2版本,整行位的许多bin比一个宽得多uint64_t:改进列填充计数算法)
我正在C中的一个项目中,我需要经历数千万个掩码(ulong类型(64位)),并target基于一个简单规则更新64个短整数(uint16)的数组(称为):
// for any given mask, do the following loop
for (i = 0; i < 64; i++) {
if (mask & (1ull << i)) {
target[i]++
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我需要在数以百万计的蒙版上执行上述循环,并且我需要在不到一秒钟的时间内完成。想知道是否有任何方法可以加快它的速度,例如使用某种表示上述循环的特殊汇编指令。
目前,我在ubuntu 14.04(i7-2670QM,支持AVX,而不是AVX2)上使用gcc 4.8.4来编译和运行以下代码,大约需要2秒钟。很想让它在200ms以下运行。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/stat.h>
double getTS() {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
unsigned int target[64];
int main(int argc, char *argv[]) {
int i, …Run Code Online (Sandbox Code Playgroud) 我遇到了一种情况,需要我根据用户输入弹出一个窗口让用户做出选择,然后根据用户输入进行另一个 http 请求。我不知道如何在弹出窗口后等待。
async function checkRemote(url1, url2) {
var resp
resp = await fetch(url1).then(r => r.json())
if (r.condition1 == 100) {
setState({showPopup: true}) //in a reactjs app
//how do I do await here to wait for the popup being closed
//get the user choice in variable "proceed"
}
if (proceed) {
resp = await fetch(url2)
//do some more work
}
}
Run Code Online (Sandbox Code Playgroud) 编写一个使用 async/await 的 web 应用程序,但在线路var r1 = await fetch(url).then((r) => r.text())似乎永远在处理的地方卡住了。我在端口 80 上侦听的 Web 服务器甚至没有收到请求。
const fetch = require ('fetch-node')
const express = require('express');
const app = express();
var savedResolve;
app.listen(8079, '127.0.0.1', function() {
console.log('listening on 8079')
})
app.get('/*', async function (req, res) {
console.log(req.path)
res.setHeader('Content-Type', 'text/html');
await task()
res.send('Done')
})
async function task() {
console.log("starting..")
var url = "http://localhost/prod/te.php";
var r1 = await fetch(url).then((r) => r.text())
console.log(r1)
return "done"
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?提前致谢!
更新1
感谢@deryck 的建议,在fetch调用行周围添加 try …
最近我遇到了一个很棒的perl模块"AnyEvent",它允许用户进行异步/事件驱动的编程.
创建了以下代码片段,工作正常.我遇到的问题是,在打开并关闭许多套接字后,它很快耗尽了所有客户端端口("netstat -ant"显示20,000多个套接字处于TIME_WAIT状态).
$hdl = new AnyEvent::Handle (
connect => [$ip, $port],
on_connect=> sub {
my ($handle, $host, $port, $tmp) = @_;
#print "connect routine for $handle->{ue}\r\n";
#update states.
},
on_read => sub {
my $hdl = $_[0];
#read data
#send response.
});
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以使用IO :: Socket :: INET创建TCP套接字,然后在AnyEvent :: Handle中使用新创建的套接字:
my $sock = IO::Socket::INET->new( Proto => 'tcp',
PeerAddr => $ue->{vars}->{ip},
PeerPort => $ue->{vars}->{dstPort},
ReusePort => 1,
KeepAlive => 1
) || die "failed to setup outsock $@\n";
$hdl = new …Run Code Online (Sandbox Code Playgroud) 这个问题可能在其他框架中被问到,不确定ExtJ上是否有一个,我是新手.我想知道是否有一个TextArea和一个按钮的简单示例.按下按钮时,固定字符串"???" 插入TextArea中的光标处.
提前致谢.
我正在尝试在我的 docker 容器中运行命令 dmidecode,
docker run --device /dev/mem:/dev/mem -it jin/ubu1604
Run Code Online (Sandbox Code Playgroud)
但它声称没有获得许可
root@bd1062dfd8ab:/# dmidecode
# dmidecode 3.0
Scanning /dev/mem for entry point.
/dev/mem: Operation not permitted
root@bd1062dfd8ab:/# ls -l /dev
total 0
crw--w---- 1 root tty 136, 0 Jan 7 03:21 console
lrwxrwxrwx 1 root root 11 Jan 7 03:20 core -> /proc/kcore
lrwxrwxrwx 1 root root 13 Jan 7 03:20 fd -> /proc/self/fd
crw-rw-rw- 1 root root 1, 7 Jan 7 03:20 full
crw-r----- 1 root kmem 1, 1 Jan …Run Code Online (Sandbox Code Playgroud) javascript ×3
asynchronous ×2
anyevent ×1
async-await ×1
c ×1
containers ×1
docker ×1
event-driven ×1
extjs ×1
linux ×1
optimization ×1
perl ×1
simd ×1
sockets ×1
textarea ×1
x86 ×1
x86-64 ×1