diff --git a/general_test.go b/general_test.go new file mode 100644 index 00000000..eb6f4701 --- /dev/null +++ b/general_test.go @@ -0,0 +1,59 @@ +package main +import "testing" +import "io/ioutil" +import "html/template" + +func BenchmarkTemplates(b *testing.B) { + user := User{0,"Bob",0,false,false,false,false,false,false,"",false,"","","","",""} + admin := User{1,"Admin",0,true,true,true,true,true,false,"",false,"","","","",""} + var noticeList map[int]string = make(map[int]string) + noticeList[0] = "test" + + topic := TopicUser{0,"Lol",template.HTML("Hey everyone!"),0,false,false,"",0,"","","",no_css_tmpl,0,"","","",""} + var replyList map[int]interface{} = make(map[int]interface{}) + replyList[0] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""} + pi := Page{"Topic Blah","topic",user,noticeList,replyList,topic} + pi2 := Page{"Topic Blah","topic",admin,noticeList,replyList,topic} + w := ioutil.Discard + + b.Run("compiled_writer_collated_useradmin", func(b *testing.B) { + for i := 0; i < b.N; i++ { + template_topic(pi2,w) + } + }) + b.Run("compiled_writer_useradmin", func(b *testing.B) { + for i := 0; i < b.N; i++ { + template_topic2(pi2,w) + } + }) + b.Run("compiled_useradmin", func(b *testing.B) { + for i := 0; i < b.N; i++ { + w.Write([]byte(template_topic3(pi2))) + } + }) + b.Run("interpreted_useradmin", func(b *testing.B) { + for i := 0; i < b.N; i++ { + templates.ExecuteTemplate(w,"topic.html", pi2) + } + }) + b.Run("compiled_writer_collated_userguest", func(b *testing.B) { + for i := 0; i < b.N; i++ { + template_topic(pi,w) + } + }) + b.Run("compiled_writer_userguest", func(b *testing.B) { + for i := 0; i < b.N; i++ { + template_topic2(pi,w) + } + }) + b.Run("compiled_userguest", func(b *testing.B) { + for i := 0; i < b.N; i++ { + w.Write([]byte(template_topic3(pi))) + } + }) + b.Run("interpreted_userguest", func(b *testing.B) { + for i := 0; i < b.N; i++ { + templates.ExecuteTemplate(w,"topic.html", pi) + } + }) +} diff --git a/gosora.exe b/gosora.exe index 3ee01cd4..e07ce32f 100644 Binary files a/gosora.exe and b/gosora.exe differ diff --git a/images/gosora-test.PNG b/images/gosora-test.PNG new file mode 100644 index 00000000..dfc527c6 Binary files /dev/null and b/images/gosora-test.PNG differ diff --git a/main.go b/main.go index 97715121..ec5cabb5 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "mime" "strings" "path/filepath" + "io" "io/ioutil" "os" "html/template" @@ -31,7 +32,7 @@ var external_sites map[string]string = make(map[string]string) var groups map[int]Group = make(map[int]Group) var forums map[int]Forum = make(map[int]Forum) var static_files map[string]SFile = make(map[string]SFile) -var ctemplates map[string]func(Page)string = make(map[string]func(Page)string) +var ctemplates map[string]func(Page,io.Writer) = make(map[string]func(Page,io.Writer)) func compile_templates() { var c CTemplateSet diff --git a/routes.go b/routes.go index 35a6c906..3181c301 100644 --- a/routes.go +++ b/routes.go @@ -413,7 +413,7 @@ func route_topic_id(w http.ResponseWriter, r *http.Request){ pi := Page{topic.Title,"topic",user,noticeList,replyList,topic} if ctemplates["topic"] != nil { - w.Write([]byte(ctemplates["topic"](pi))) + ctemplates["topic"](pi,w) } else { err = templates.ExecuteTemplate(w,"topic.html", pi) if err != nil { diff --git a/template_profile.go b/template_profile.go index 5e69cfad..5c4ca506 100644 --- a/template_profile.go +++ b/template_profile.go @@ -1,176 +1,130 @@ package main +import "io" import "strconv" func init() { ctemplates["profile"] = template_profile } -func template_profile(tmpl_profile_vars Page) (tmpl string) { +func template_profile(tmpl_profile_vars Page, w io.Writer) { var extra_data User = tmpl_profile_vars.Something.(User) -tmpl += ` +w.Write([]byte(`
-