Is it faster to read raw json files or jsonified C# classes?
It is easier for me to create the data my site uses in a .cshtml file that
instantiates N objects of a class (as opposed to creating a .json file). I
only recently changed to this method, after previously creating raw json
files.
The code to read the data, whether .json or .cshtml, is the same:
$.getJSON('Content/nba.json', function (data) {
$.each(data, function (i, dataPoint) {
. . .
$.getJSON('getHugos.cshtml', function (data) {
$.each(data, function (i, dataPoint) {
. . .
Presumably, reading raw json, like such:
. . .
{
"category":"Outdoor Literature",
"title":"Almost Somewhere: Twenty-Eight Days on the John Muir Trail",
"author":"Suzanne Roberts",
"kindle":"B008SAOT4C",
"hardbound":"--",
"paperback":"0803240120",
"imghref":"http://rads.stackoverflow.com/amzn/click/B008SAOT4C"
target=\"_blank\" ><img height=\"180\" width=\"120\"
src=\"http://images.amazon.com/images/P/B008SAOT4C.01.MZZZZZZZ.jpg\"
alt=\"Suzanne Roberts Book Cover\" /></a>"
},
. . .
...would be more performant than this sort of thing:
new Book {category='Best Novel', ... };
// jsonify and return the data above
...which has to go through the additional step via ASP.NET of being
converted to this:
[...,{"Year":2013,"YearDisplay":"2013","Category":"Best
Novel","Title":"Redshirts","Author":"John
Scalzi","KindleASIN":"B0079XPUOW","HardboundASIN":"0765316994","PaperbackASIN":"0765334798","ImgSrc":"http://images.amazon.com/images/P/B0079XPUOW.01.MZZZZZZZ"},...]
...but as we all know, presuming things sometimes gets us into trouble.
I know what you're thinking - just test it and find out; but I haven't
created enough of the cshtml records yet to be able to compare the two
approaches, but wonder if anybody knows whether the speed of loading raw
json files would be noticeably speedier than converting the C# classes
into json data? If so, I might have to revert to my previous
methodology...
No comments:
Post a Comment