You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
790 B
45 lines
790 B
7 years ago
|
/*
|
||
|
* Copyright (c) 2018-present, Facebook, Inc.
|
||
|
*
|
||
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
|
*/
|
||
|
package codetoanalyze.java.performance;
|
||
|
|
||
|
public class Switch{
|
||
|
// Cost 51
|
||
|
private static void vanilla_switch(int i){
|
||
|
|
||
|
for (int p = 0; p < 100; p++)
|
||
|
{
|
||
|
switch (p) {
|
||
|
case 0:
|
||
|
i++;
|
||
|
break;
|
||
|
case 1: case 2: case 3:
|
||
|
break;
|
||
|
default:
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//797
|
||
|
private static int test_switch() {
|
||
|
int value = 0;
|
||
|
// infinite loop
|
||
|
while (value < 100) {
|
||
|
switch (value) {
|
||
|
case 0:
|
||
|
break;
|
||
|
case 1:
|
||
|
continue;
|
||
|
case 2:
|
||
|
default:
|
||
|
continue;
|
||
|
}
|
||
|
value++;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
}
|