Guest User

Untitled

a guest
Jun 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. import std.random;
  2. import std.stdio;
  3. import core.stdc.stdlib : bsearch;
  4.  
  5. int[1000] a;
  6.  
  7. extern(C)
  8. int compareints(in void * a, in void * b)
  9. {
  10. return *cast(int*)a - *cast(int*)b;
  11. }
  12.  
  13. void main()
  14. {
  15. foreach (ref n; a)
  16. n = rand()%1000;
  17. a.sort;
  18.  
  19. foreach (iter; 0..100_000_000)
  20. {
  21. int key = rand()%1000;
  22. bsearch(&key, a.ptr, a.length, a[0].sizeof, &compareints);
  23. }
  24. }
Add Comment
Please, Sign In to add comment