我正在试图弄清楚如何正确使用Java的Executors.我意识到将任务提交给ExecutorService有自己的开销.但是,我很惊讶它看到它的高度.
我的程序需要以尽可能低的延迟处理大量数据(股票市场数据).大多数计算都是相当简单的算术运算.
我试着测试一些非常简单的东西:" Math.random() * Math.random()"
最简单的测试在一个简单的循环中运行这个计算.第二个测试在匿名Runnable中进行相同的计算(这应该衡量创建新对象的成本).第三测试传递Runnable到一个ExecutorService(在此测定引入执行人的成本).
我在我的小型笔记本电脑上运行测试(2 cpus,1.5 gig ram):
(in milliseconds)
simpleCompuation:47
computationWithObjCreation:62
computationWithObjCreationAndExecutors:422
Run Code Online (Sandbox Code Playgroud)
(大约四次运行中,前两个数字最终相等)
请注意,执行程序所花费的时间远远多于在单个线程上执行的时间.对于1到8之间的线程池大小,数字大致相同.
问题:我是否遗漏了一些明显的或者预期的结果?这些结果告诉我,我传递给执行程序的任何任务都必须进行一些非平凡的计算.如果我正在处理数百万条消息,并且我需要对每条消息执行非常简单(且便宜)的转换,我仍然可能无法使用执行程序...尝试在多个CPU之间传播计算可能最终会比仅仅更昂贵在一个线程中完成它们.设计决策变得比我原先想象的要复杂得多.有什么想法吗?
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class ExecServicePerformance {
private static int count = 100000;
public static void main(String[] args) throws InterruptedException {
//warmup
simpleCompuation();
computationWithObjCreation();
computationWithObjCreationAndExecutors();
long start = System.currentTimeMillis();
simpleCompuation();
long stop = System.currentTimeMillis();
System.out.println("simpleCompuation:"+(stop-start));
start = System.currentTimeMillis();
computationWithObjCreation();
stop = System.currentTimeMillis();
System.out.println("computationWithObjCreation:"+(stop-start));
start = System.currentTimeMillis();
computationWithObjCreationAndExecutors();
stop = System.currentTimeMillis();
System.out.println("computationWithObjCreationAndExecutors:"+(stop-start)); …Run Code Online (Sandbox Code Playgroud) 是否有用于实现iGoogle风格仪表板的jquery插件?所以基本上拖动n drop风格等.
谢谢
我最近发现了这个:
http://www.webappers.com/2008/11/19/how-to-create-igoogle-interface-with-jquery/
希望有帮助......
我试图循环文本文件的目录,并将它们组合成一个文档.这很好用,但文本文件包含代码片段,我的所有格式都被折叠到左侧.一条线上的所有前导空格都被剥离.
#!/bin/sh
OUTPUT="../best_practices.textile"
FILES="../best-practices/*.textile"
for f in "$FILES"
do
echo "Processing $f file..."
echo "">$OUTPUT
cat $f | while read line; do
echo "$line">>$OUTPUT
done
echo >>$OUTPUT
echo >>$OUTPUT
done
Run Code Online (Sandbox Code Playgroud)
我当然是一个bash noob,但经过高低搜索我无法找到合适的解决方案.显然,BASH一般都讨厌领先的白色空间.
作为标题,当我将元素插入到objective-c中的字典(按顺序如:k1,k2,k3)时,是否有任何保证,当我枚举它时:
for ( k in dictionary ){
// output the k - value
}
Run Code Online (Sandbox Code Playgroud)
它会以相同的顺序显示?
我尝试使用jQuery的AJAX函数覆盖HTTP请求标头内容.看起来像这样
$.ajax({
type : "POST",
url : url,
data : data,
contentType: "application/x-www-form-urlencoded;charset=big5",
beforeSend: function(xhr) {
xhr.setRequestHeader("Accept-Charset","big5");
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=big5");
},
success: function(rs) {
target.html(rs);
}
});
Run Code Online (Sandbox Code Playgroud)
Content-Type标头默认为"application/x-www-form-urlencoded; charset = UTF-8",但显然无论我使用'contentType'还是'beforeSend'方法,我都无法覆盖它的值.任何人都可以向我提示我如何更改HTTP请求的内容类型值?非常感谢.
顺便说一下,有什么好的文档可以研究JavaScript的XMLHttpRequest的编码处理吗?
我有一个方法Foo4接受类型为Func <>的参数.如果我传递一个匿名类型的参数,我没有错误.但是,如果我创建并传递一个引用具有正确签名的Method的"委托"类型的对象,则会出现编译器错误.在这种情况下,我无法理解为什么我会收到错误.
class Learn6
{
delegate string Mydelegate(int a);
public void Start()
{
Mydelegate objMydelegate = new Mydelegate(Foo1);
//No Error
Foo4(delegate(int s) { return s.ToString(); });
//This line gives compiler error.
Foo4(objMydelegate);
}
public string Foo1(int a) { return a.ToString();}
public void Foo4(Func<int, string> F) { Console.WriteLine(F(42)); }
}
Run Code Online (Sandbox Code Playgroud) 有没有免费的分析工具,我可以独立测量HTML,PHP和JavaScript代码的性能?
那么这个文件被错误地放入了回购中并被删除并添加到忽略列表中.但是,因为它曾经存在,我的repo现在大小超过4GB,一些SVN功能需要数年时间才能完成.我将不胜感激任何帮助和提示.(如果重要,我会使用XP)
有没有办法在访问时自动锁定STL容器,而不必锁定和释放它?
我正在使用keydown事件
我在哪里获得密码并将其转换为charcode.
但我遇到了一个问题,在键盘按下2它给出50和charcode为2
当我按下2numpad它会给出98keycode,所以当我转换charcode时a
javascript ×3
.net ×1
ajax ×1
bash ×1
boost-thread ×1
c# ×1
c#-3.0 ×1
c++ ×1
cat ×1
containers ×1
delegates ×1
dictionary ×1
encoding ×1
events ×1
html ×1
java ×1
jquery ×1
objective-c ×1
parsing ×1
performance ×1
php ×1
repository ×1
stl ×1
svn ×1
text-files ×1
windows ×1