我发现在java中计算sha256很慢.例如,它比python慢.我写了两个简单的基准测试来计算1GB零的sha256.在这两种情况下,结果都是相同且正确的,但是python时间是5653ms,java时间是8623ms(慢了53%).结果每次都相似,这对我来说是一个重要的区别.
如何更快地在java中进行计算?
基准:
Java的:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class BenchmarkSha256 {
public static void main(String... args) throws NoSuchAlgorithmException {
int size = 1024 * 1024;
byte[] bytes = new byte[size];
MessageDigest md = MessageDigest.getInstance("SHA-256");
long startTime = System.nanoTime();
for (int i = 0; i < 1024; i++)
md.update(bytes, 0, size);
long endTime = System.nanoTime();
System.out.println(String.format("%1$064x", new java.math.BigInteger(1, md.digest())));
System.out.println(String.format("%d ms", (endTime - startTime) / 1000000));
}
}
Run Code Online (Sandbox Code Playgroud)
蟒蛇:
#!/usr/bin/env python
import hashlib
import time
size = 1024 * 1024 …Run Code Online (Sandbox Code Playgroud) 我正在使用嵌入式模式的H2数据库工作java应用程序.我的应用程序消耗150mb的堆内存.
问题:步骤当我用2 mb的数据加载H2数据库时,数据库访问速度很快,堆内存大小为160mb.
但是,当我使用30 mb的数据(h2 db文件大小= 30 mb)加载H2数据库时.然后从我的应用程序访问数据库非常慢.原因是我的应用程序堆大小已经大大增加到300mb的大小因此降低了性能.我确认使用JConsole.
所以我的理解是因为H2数据库是使用java开发的,因为我在嵌入模式下使用H2数据库,H2数据库的堆大小被添加到我的应用程序中,这打破了应用程序.
问题是随着H2数据库大小的增长,我的应用程序的性能降低了.
如何解决这个问题?
我把连接作为
rurl = "jdbc:h2:file:/" + getDBPath() + dbname + ";CACHE_SIZE=" + (1024 * 1024) + ";PAGE_SIZE=512";
Run Code Online (Sandbox Code Playgroud)
增加H2的缓存.
我需要向所有消费者发送消息,但在检测谁应该收到此消息之前,如何使用 Kafka 做到这一点?
我应该使用 Kafka 流来过滤数据然后发送给消费者吗?据我所知,每个消费者都应该添加到唯一的消费者组中,但是如何实时检测谁必须接收消息?
我正在尝试优化我的python代码.当我尝试根据每个元素值将函数应用于numpy数组时,出现了一个瓶颈.例如,我有一个包含数千个元素的数组,我为一个大于公差的值应用一个函数,为其余的函数应用另一个函数(泰勒系列).我做掩蔽但仍然很慢,至少我调用了6400万次以下的功能.
EPSILONZETA = 1.0e-6
ZETA1_12 = 1.0/12.0
ZETA1_720 = 1.0/720.0
def masked_condition_zero(array, tolerance):
""" Return the indices where values are lesser (and greater) than tolerance
"""
# search indices where array values < tolerance
indzeros_ = np.where(np.abs(array) < tolerance)[0]
# create mask
mask_ = np.ones(np.shape(array), dtype=bool)
mask_[[indzeros_]] = False
return (~mask_, mask_)
def bernoulli_function1(zeta):
""" Returns the Bernoulli function of zeta, vector version
"""
# get the indices according to condition
zeros_, others_ = masked_condition_zero(zeta, EPSILONZETA)
# create an array …Run Code Online (Sandbox Code Playgroud) 抱歉,这可能是一个基本问题。JNA直接映射和接口映射有什么区别?
我的解释正确吗:
直接映射:直接使用库对象(例如Java中的static main)
接口映射:创建库对象的实例。
提前致谢!
我对Vert.x很新,请原谅我的新闻.
我能够使用Vert.x创建一个非常简单的SockJS服务器,但是当连接打开或关闭时,我无法弄清楚如何注册事件/回调/处理程序.
使用JSR-356,它可以简单地处理打开/关闭连接事件:
@OnOpen
public void onOpen(Session userSession) {
// Do whatever you need
}
@OnClose
public void onClose(Session userSession) {
// Do whatever you need
}
Run Code Online (Sandbox Code Playgroud)
使用Spring Framework 4.0 M1 +中的SockJS支持,它与JSR-356几乎相同:
public class MySockJsServer extends TextWebSocketHandlerAdapter {
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
// Do whatever you need
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
// Do whatever you need
}
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我无法弄清楚在Vert.x中如何在概念上做一些简单的事情.我虽然Vert.x很简单?!!
如果有人能指出我正确的方向,请帮助.
我玩了EventBus和EventBus钩子,但它没有用.也许这是错误的方法无论如何.
我正在使用Vert.x版本2.0.1
TIA
众所周知,有:https://www.kernel.org/doc/Documentation/networking/scaling.txt
这是否意味着:
那是对的吗?
基本上每次我从eclipse运行我的java代码时,webdriver都会启动一个新的ie浏览器并在大多数情况下成功执行我的测试.但是,我有很多测试要运行,webdriver每次启动一个新的浏览器会话都很痛苦.我需要一种方法来重用以前打开的浏览器; 所以webdriver会打开,即第一次,然后第二次,我运行我的eclipse程序,我希望它只是拿起以前的浏览器实例并继续在同一个实例上运行我的测试.这样,我每次运行程序时都不会启动新的浏览器会话.
假设您有100个测试要在eclipse中运行,您点击该运行按钮并且它们都运行,然后在大约第87次测试时您会收到错误.然后你回到eclipse,修复那个错误,但是你必须从头再次重新运行所有100个测试.
在第87次测试中修复错误然后从第87次测试恢复执行,而不是从头开始重新执行所有测试,即从测试0一直到100,这将是很好的.希望,我很清楚你们的帮助,谢谢顺便说一下.
以下是我尝试维护和重新使用webdriver Internet Explorer浏览器实例的尝试:
public class demo extends RemoteWebDriver {
public static WebDriver driver;
public Selenium selenium;
public WebDriverWait wait;
public String propertyFile;
String getSessionId;
public demo() { // constructor
DesiredCapabilities ieCapabilities = DesiredCapabilities
.internetExplorer();
ieCapabilities
.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
driver = new InternetExplorerDriver(ieCapabilities);
this.saveSessionIdToSomeStorage(getSessionId);
this.startSession(ieCapabilities);
driver.manage().window().maximize();
}
@Override
protected void startSession(Capabilities desiredCapabilities) {
String sid = getPreviousSessionIdFromSomeStorage();
if (sid != null) {
setSessionId(sid);
try {
getCurrentUrl();
} catch (WebDriverException e) {
// session is not valid
sid …Run Code Online (Sandbox Code Playgroud) java selenium browser-automation selenium-webdriver remotewebdriver
我试图使用看起来像这样的代码编译项目
#include <tuple>
#include <utility>
struct Foo
{
};
template <typename... Args>
void start(Args&&... args) {
auto x = [args = std::make_tuple(std::forward<Args>(args)...)] () mutable {
auto y = [args] () mutable {
auto z = [] (Args&&... args) {
return new Foo(std::forward<Args>(args)...);
};
};
};
}
int main()
{
start(Foo{});
}
Run Code Online (Sandbox Code Playgroud)
似乎在GCC 4.9.1中编译良好,但在Clang 3.4,3.5,3.6中没有编译.错误消息是
错误:变量'args'不能在没有指定capture-default的lambda中隐式捕获
这是编译器错误吗?如果是这样,是否有任何解决方法让它在Clang上编译?
我使用以下命令在OpenTSDB中为测试目的制作了两个metrices:
./build/tsdb mkmetric temperatures
./build/tsdb mkmetric meterreadings
Run Code Online (Sandbox Code Playgroud)
我还在这些metrices中使用Java输入数据点:
put temperatures 1356998400 23.5 room=bedroom floor=1\n
put meterreading 1430568000 32800 accumulationBehaviour=4 commodity=1 dataQualifier=12 defaultQuality=0 flowDirection=1 intervalLength=900 intervalLength=900 kind=12 phase=769 powerOfTenMultiplier=0 timeAttribute=0 uom=72
put meterreading 1430568900 33624 accumulationBehaviour=4 commodity=1 dataQualifier=12 defaultQuality=0 flowDirection=1 intervalLength=900 intervalLength=900 kind=12 phase=769 powerOfTenMultiplier=0 timeAttribute=0 uom=72
put meterreading 1430569800 35192 accumulationBehaviour=4 commodity=1 dataQualifier=12 defaultQuality=0 flowDirection=1 intervalLength=900 intervalLength=900 kind=12 phase=769 powerOfTenMultiplier=0 timeAttribute=0 uom=72
put meterreading 1430570700 37928 accumulationBehaviour=4 commodity=1 dataQualifier=12 defaultQuality=0 flowDirection=1 intervalLength=900 intervalLength=900 kind=12 phase=769 powerOfTenMultiplier=0 timeAttribute=0 uom=72
Run Code Online (Sandbox Code Playgroud)
现在我想删除所有数据和矩阵,以便OpenTSDB表现为全新安装.
在他们使用scan命令提到的文档中,我不知道如何使用此命令.
java ×3
optimization ×2
apache-kafka ×1
c++ ×1
c++14 ×1
clang++ ×1
h2 ×1
hbase ×1
jna ×1
linux ×1
linux-kernel ×1
networking ×1
numpy ×1
opentsdb ×1
performance ×1
python ×1
selenium ×1
sha ×1
sha256 ×1
sockjs ×1
tcp ×1
vert.x ×1