Skip to content

Instantly share code, notes, and snippets.

@Vzor-
Last active June 30, 2023 23:40
Show Gist options
  • Save Vzor-/0a4d5f2883dcfc4539426b6948c029ca to your computer and use it in GitHub Desktop.
Save Vzor-/0a4d5f2883dcfc4539426b6948c029ca to your computer and use it in GitHub Desktop.
A test to display the slowdown associated with PrintService.getName()
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
public class ServiceTest {
public static void main(String[] args) {
long n = 0;
// System.setProperty("sun.java2d.print.polling", "false");
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
while (true) {
long start = System.nanoTime();
for (int i = 0; i < 1000; i++)
services[0].getName(); //must have at least 1 print service for this test
n += 1000;
System.out.printf("time: %.3fms per, after %d calls\n", (System.nanoTime() - start) / 1000000000.0, n);
}
}
}
// Example output:
// time: 2.676ms per, after 1000 calls
// time: 3.259ms per, after 2000 calls
// time: 4.275ms per, after 3000 calls
// time: 5.316ms per, after 4000 calls
// time: 6.358ms per, after 5000 calls
// time: 7.341ms per, after 6000 calls
// time: 7.556ms per, after 7000 calls
// time: 8.606ms per, after 8000 calls
// time: 9.295ms per, after 9000 calls
// time: 9.585ms per, after 10000 calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment