a tiny c-template work-alike for java
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

48 lines
1.3 KiB

  1. package com.binarythought.picotemplate.example;
  2. import com.binarythought.picotemplate.Template;
  3. import com.binarythought.picotemplate.TemplateDictionary;
  4. import java.io.File;
  5. public class TemplateExample {
  6. public static void main(String args[]) throws Exception
  7. {
  8. Template template = new Template(new File("res/test.html"));
  9. TemplateDictionary dict = new TemplateDictionary();
  10. dict.put("object1", "rifle");
  11. dict.show("section");
  12. TemplateDictionary d1 = dict.createChild("section");
  13. d1.put("object2", "fighting");
  14. TemplateDictionary d2 = dict.createChild("section");
  15. d2.put("object2", "fun");
  16. System.out.println("*** Parsed Template: ");
  17. System.out.println(template.parse(dict));
  18. long t = System.currentTimeMillis();
  19. template.parse(dict);
  20. System.out.println("1 Template: "+(System.currentTimeMillis()-t)+"ms");
  21. t = System.currentTimeMillis();
  22. for(int i=0;i < 1000; i++){
  23. template.parse(dict);
  24. }
  25. System.out.println("1000 Templates: "+(System.currentTimeMillis()-t)+"ms");
  26. t = System.currentTimeMillis();
  27. for(int i=0;i < 10000; i++){
  28. template.parse(dict);
  29. }
  30. System.out.println("10000 Templates: "+(System.currentTimeMillis()-t)+"ms");
  31. t = System.currentTimeMillis();
  32. for(int i=0;i < 100000; i++){
  33. template.parse(dict);
  34. }
  35. System.out.println("100000 Templates: "+(System.currentTimeMillis()-t)+"ms");
  36. }
  37. }