Guest User

Untitled

a guest
Oct 24th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. import java.util.BitSet;
  2. import java.util.concurrent.Semaphore;
  3.  
  4. public class Main {
  5.  
  6.      private static final int THREADS = 4;
  7.      private static final int N= 60;
  8.      public static Semaphore semaphore = new Semaphore(1);
  9.      
  10.        
  11.      public static BitSet set;
  12.      public static int size;
  13.      public static int x;
  14.      public static int maximum;
  15.            
  16.         public Main(int x) {
  17.             size = x + 1;
  18.             set = new BitSet(size);
  19.             set.flip(2, size);
  20.             maximum = (int) Math.floor(Math.sqrt(size)+1);
  21.  
  22.            
  23.         }
  24.    
  25.     public static void main(String[] args) throws InterruptedException {
  26.          
  27.                 Main bitSetSieveMain = new Main(N);
  28.                 Thread [] threadsTab = new Thread[THREADS];
  29.                
  30.                 for(int i=0; i<threadsTab.length; i++) threadsTab[i] = new Thread(new Sito(i));
  31.                
  32.                 long start = System.nanoTime();
  33.                
  34.                
  35.                
  36.                
  37.                 for(int i=0; i<threadsTab.length; i++)
  38.                 {
  39.                     threadsTab[i].start();
  40.  
  41.                 }
  42.                 for(int i=0; i<threadsTab.length; i++)
  43.                 {
  44.                     threadsTab[i].join();
  45.                 }
  46.  
  47.                 long time = System.nanoTime() - start;
  48.                
  49.                
  50.                
  51.                 System.out.println(time/10000  + " nano seconds to perform " + set.length() + " numbers " + bitSetSieveMain);
  52.                 System.out.println(Main.set.cardinality());
  53.                
  54.            
  55.  
  56.     }
  57.    
  58.    
  59.    
  60.    
  61.  
  62.     public String toString() {
  63.         return set.toString();
  64.     }
  65.    
  66.    
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment