dreamworker

Untitled

Mar 29th, 2021
1,863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. public inline class Vector {
  2.  
  3.     private final double x;
  4.     private final double y;
  5.  
  6.     public Vector(double x, double y) {
  7.         this.x = x;
  8.         this.y = y;
  9.     }
  10.  
  11.     public Vector add(Vector v) {
  12.         return new Vector(x + v.x, y + v.y);
  13.     }
  14.  
  15.     @Override
  16.     public String toString() {
  17.         return "{" + x + "," + y + "}";
  18.     }
  19.  
  20. }
  21.  
  22. TEST:
  23.  
  24. Instant start = Instant.now();
  25. Vector v = new Vector(0, 0);
  26. for (long i = 0; i < 5000000000L; i++) {
  27.     v = v.add(v);
  28. }
  29.  
  30. Instant end = Instant.now();
  31. Duration d = Duration.between(start,end);
  32. System.out.println(d + v.toString());
  33.  
  34.    
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment