Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://www.compilejava.net/
- //*******************************************************************
- // Java compiler created in PHP to quickly and safely test code.
- // NOTE: please read the 'More Info' tab to the right for shortcuts.
- //*******************************************************************
- import java.lang.Math; // header stuff MUST go above the first class
- // our main class becomes a file but the main method is still found
- public class HelloWorld
- {
- public static void main(String[] args)
- {
- String s = "";
- int i = 0, j = 0;
- for (i = 0; i < 10; i++)
- s += "aqw1ert2x4";
- long start_time = System.currentTimeMillis();
- long count = 0;
- for (j = 0; j < 1000000; j++) {
- /* * /
- for (i = 0; i < s.length(); i++) {
- if (Character.isDigit(s.charAt(i)))
- count++; // 259 ms
- }
- /* */
- long cnt = s.codePoints().filter(Character::isDigit).count();
- count += cnt; // 1405 ms
- /* */
- }
- long stop_time = System.currentTimeMillis();
- System.out.println("count " + count + " " + (stop_time - start_time));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement