I was playing around with IronJS, trying to allow a Javascript filter function be defined dynamically (as a string in .Net) and be applied to some piece of JSON data (again, coming in as a string in .Net). However, I'm not seeing the performance I would need for what I had in mind - and that may just be the limit of the DLR etc, and that's fine. But before I drop the idea of using a IronJs, I just wanted to be sure I wasn't doing anything silly
I've included my spike code below. On my machine, it executes the function about 400 times a second. Is there a more efficient way to do this?
let testIronJs(count) =
let testMessage = @"{ 'someData':'blah' }"
let testPredicate = @"function(data) {
return data.someData === 'blah';
}"
let ctx = IronJS.createContext()
let sw = new Stopwatch()
sw.Start()
// just defining function in global scope for quick test
let fn = sprintf "testFn=%s;" testPredicate
ctx |> execute fn |> ignore
for i in 1..count do
let script = sprintf "testFn(%s);" testMessage
let result = ctx |> executeAs<bool> script
if result <> true then raise(new Exception("Unexpected result"))
()
sw.Stop()
sw.Elapsed
let main() =
let count = 1000
let timeTaken = testIronJs(count)
printf "%d in %s\n%f/sec\n" count (timeTaken.ToString()) ((float count/timeTaken.TotalMilliseconds) * 1000.0)
()
main()