0%

数组 [2,2,3,4,9,3] 给一个元素 6 找出数组中两个元素之和等于它,并返回数组坐标。思路:使用mapkey用来记录arr[i]的值,value用来记录对应的下标,使用 containsKey 或者 get 进行逻辑判断 arr[?] = target - arr[??]

@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 3)
@Measurement(iterations = 10, time = 5, timeUnit = TimeUnit.SECONDS)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class TestFindArrayIndex {

@Benchmark
public int[] findIndexOfArray1() {
int[] arr = new int[] {2,2,3,4,9,3}; int target = 6;
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < arr.length; i++) {
if (map.containsKey(target - arr[i])) {
return new int[] {map.get(target - arr[i]),i};
}
map.put(arr[i], i);
}
return null;
}

@Benchmark
public int[] findIndexOfArray2() {
int[] arr = new int[] {2,2,3,4,9,3}; int target = 6;
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < arr.length; i++) {
if (map.get(arr[i]) != null) {
return new int[]{map.get(arr[i]), i};
}
map.put(target - arr[i], i);
}
return null;
}

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(TestFindArrayIndex.class.getSimpleName())
.output("Benchmark.log")
.forks(1)
.build();
new Runner(opt).run();
}
}

给出了两个性能差不多的方案,使用 JMH 性能测试,更多例子参考 ,影响基准测试的因素比较多,包括代码预热、编译器动态优化、资源回收(GC)、文件缓存、电源、其他程序,JVM的VM选项等等,详细参考

阅读全文 »

Here's something encrypted, password is required to continue reading.
阅读全文 »

Here's something encrypted, password is required to continue reading.
阅读全文 »

源码

Thus “FooBah” becomes “fooBah” and “X” becomes “x”, but “URL” stays as “URL”.
如果一个类名是以两个大写字母开头的,则首字母不变,其它情况下默认首字母变成小写。

/**
* Utility method to take a string and convert it to normal Java variable
* name capitalization. This normally means converting the first
* character from upper case to lower case, but in the (unusual) special
* case when there is more than one character and both the first and
* second characters are upper case, we leave it alone.
* <p>
* Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays
* as "URL".
*
* @param name The string to be decapitalized.
* @return The decapitalized version of the string.
*/
public static String decapitalize(String name) {
if (name == null || name.length() == 0) {
return name;
}
if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
Character.isUpperCase(name.charAt(0))){
return name;
}
char chars[] = name.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
return new String(chars);
}

Here's something encrypted, password is required to continue reading.
阅读全文 »

执行步骤

查看 docker search vsftpd

NAME                                     DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
fauria/vsftpd vsftpd Docker image based on Centos 7. Suppo… 153 [OK]
panubo/vsftpd vsftpd - Secure, fast FTP server 36 [OK]
vimagick/vsftpd 13 [OK]
odiobill/vsftpd Very light vsftpd installation based on Debi… 7 [OK]
million12/vsftpd VSFTPD Server in a Docker 7 [OK]
emilybache/vsftpd-server 6 [OK]
avenus/vsftpd-alpine Docker image of vsftpd server based on Alpin… 5 [OK]
wildscamp/vsftpd An FTP server designed to simplify local dev… 4 [OK]
loicmathieu/vsftpd vsftpd container 2 [OK]
akue/vsftpd vsftpd Docker image based on Centos 7. Suppo… 1
hiproz/vsftpd an vsftpd that support virtual user which ha… 1
benssson/vsftpd copy of wildscamp/vsftpd but with pasv_addr_… 1 [OK]
instantlinux/vsftpd A clean, easy-to-use, tiny yet full-featured… 1 [OK]
mikenye/vsftpd-anon-uploads A generic, ready-to-go anonymous ftp server … 1 [OK]
undying/vsftpd Vsftpd Docker Container 0 [OK]
ledermann/vsftpd Clone of helderco/docker-vsftpd, just to pro… 0
dmanas/vsftpd-mysql 0
dolphyvn/vsftpd_priv 0
markhobson/vsftpd 0
valus/vsftpd vsftpd on CentOS 7 for internal usage. 0
shourai/vsftpd-alpine vsftpd based on alpine 0
ernestas/vsftpd-server simple vsftpd server 0 [OK]
openmicroscopy/vsftpd-anonymous-upload Vsftpd Docker image for anonymous FTP upload… 0 [OK]
zloystrelok/vsftpd fixed fork vsftpd 0
vistrcm/vsftpd This Docker container implements a vsftpd se… 0 [OK]

阅读全文 »

Here's something encrypted, password is required to continue reading.
阅读全文 »