例举2个例子:1使用Iterator对象遍历集合时,此时遍历前检查集合大小可以缩短执行时间约为:64%
public static void main(String[] args) { int N = 1000 * 100000; List<Integer> list = new ArrayList<Integer>();
long start = System.currentTimeMillis(); for (int i = 0; i < N; i++) { Iterator<Integer> iter = list.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } }
System.out.println(System.currentTimeMillis() - start); //==================490 start = System.currentTimeMillis(); for (int i = 0; i [...]
tech's archives
性能准则之一:在遍历集合前一定要判断集合是否为空
Posted by zeaster in March 15th 2007
active mode OR passive mode on FTP
Posted by zeaster in January 25th 2007
自从给小黑装上了Mac OS X就再也不想用windows了,不管是xp还是vista,都太蹩脚了在公司和同事传文件时,苹果自带的ftp服务器就派上了用途。苹果自带的这个ftp服务器还是很好用的,不需要配置,只需要在sharing中启动ftp服务,打开防火墙就OK了。但接下来也遇到了一点点麻烦:同事使用windows自带的ftp命令行工具则可以访问我的ftp服务器,使用flashFXP则无法访问。后来证实是因为ftp命令行使用active mode(主动模式)所以可以访问,而flashFXP选用passive mode(被动模式)无法访问,不选用被动模式则可以正常访问。
于是google之:看到这篇文章,疑惑顿释。主动模式和被动模式是相对于ftp服务器来说的,即是ftp服务器主动同客户端建立通讯socket或ftp服务器被动接受客户端发来的建立通讯socket请求。ftp以及telnet等老式的通信协议使用了2种端口,一个是命令端口(Command Port),另一个是数据端口(Data Port)ftp的命令端口是21,这个端口在苹果防火墙设置中被开放。但另一个数据端口是在通信时由客户端随机指定的,如果使用被动模式,客户端使用数据端口进行通信时就会被Mac的防火墙拦住。而使用主动模式时,是ftp服务器使用数据端口和同事的机器建立socket,而同事机器上没有防火墙,因此可以正常访问。
后来,在同事机器上装了天网防火墙,建立了若干规则,很容易就验证了上述想法。
literate programming about leo
Posted by zeaster in January 18th 2007
早上看看了文学编程IDE:leo ,读的是这篇教程,写的简单易懂,很适合初学者,感觉比leo自带的doc好。leo使用@file命令导入文件后,使用<<>>标记会在原文件中添加信息,这样做会使原文件看起来有些凌乱。
Search
Most Comments
- blogsync with gui coming, import your wordpress to blogger (68)
- blogsync 0.3 released, comments can be imported. (20)
- A tool that import all posts from wordpress to blogger in python (8)
- Mac OS X上成功使用dopod 696 wm5.0 连 cmwap上网 (7)
- blogsync 2.0 released, import your wordpress to blogger from rss xml file or online (5)
- How to decompile .dex file on Android (4)
- Inconvenienced when using Contact Content Provider on Android (3)
- 统一Mac OS X,Windows XP/Vista以及linux的系统时间 (2)
- Windows XP/Vista vs Mac OS X 软件对比清单 (2)
- 性能准则之一:在遍历集合前一定要判断集合是否为空 (2)
- A python script that get posts from wordpress by httplib (1)
- blogsync FAQ (1)
Recent Comments
- zeaster in blogsync 0.3 released, comments can…
- the writer in blogsync 0.3 released, comments can…
- zeaster in Inconvenienced when using Contact C…
- sshwsfc in Inconvenienced when using Contact C…
- zeaster - How t… in Inconvenienced when using Contact C…
- zeaster - Incon… in How to decompile .dex file on Andro…
- meng_xx in How to decompile .dex file on Andro…
- Elia in blogsync with gui coming, import yo…
- Yichao in blogsync with gui coming, import yo…
- Elia in blogsync with gui coming, import yo…