Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PROFILE_AND_VERIFY new /datum/profile_and_verify
- /datum/profile_and_verify
- var/list/callbacks
- var/sample_size
- var/random_input
- var/compare_output
- /datum/profile_and_verify/New(_sample_size, _random_input, _compare_output, ...)
- sample_size = _sample_size
- random_input = _random_input
- compare_output = _compare_output
- callbacks = args.Copy(4)
- start()
- /datum/profile_and_verify/proc/start()
- var/list/options = list()
- for(var/i in 1 to callbacks.len)
- options += i
- var/percent_done = 0
- var/hundredth = CEILING(sample_size / 100, 1)
- for(var/i in 1 to sample_size)
- var/list/current_run = options.Copy()
- var/list/input
- if(random_input)
- input = call(random_input)()
- if(!istype(input, /list))
- input = list(input)
- var/list/current_outputs = list()
- while(current_run.len)
- var/choice = pick(current_run)
- current_run -= choice
- var/callback = callbacks[choice]
- var/output = call(callback)(arglist(input))
- if(compare_output)
- var/bad_output = FALSE
- for(var/k in 1 to length(current_outputs))
- bad_output = call(compare_output)(output, current_outputs[k]) || bad_output
- if(bad_output)
- var/usr_out = "A tested proc has different outputs than the others:\nproc:[callback]\noutput:[bad_output]\nargs:"
- for(var/k in 1 to input.len)
- usr_out = "[usr_out] \"[input[k]]\""
- usr << usr_out
- sleep(1)
- current_outputs += list(output)
- if(i % hundredth == 0)
- usr << "profile [++percent_done]% done"
- sleep(1)
- //////////////////////////////////////////////////////////////////////////EXAMPLE
- /obj/fake_port
- var/width
- var/dwidth
- var/height
- var/dheight
- /mob/verb/profile_ordered_turfs()
- PROFILE_AND_VERIFY(
- 1000000,
- .proc/rand_ordered,
- .proc/compare_ordered,
- .proc/new_return_ordered_turfs,
- .proc/old_return_ordered_turfs,
- )
- /proc/rand_ordered()
- var/obj/fake_port/fake_port = new()
- fake_port.width = rand(1, 100)
- fake_port.height = rand(1, 100)
- fake_port.dwidth = rand(-100, 100)
- fake_port.dheight = rand(-100, 100)
- fake_port.dir = pick(list(1, 2, 4, 8))
- return list(rand(1, 100), rand(1, 100), rand(1, 10), pick(list(1, 2, 4, 8)), fake_port)
- /proc/compare_ordered(var/list/output1, var/list/output2)
- if(length(output1) != length(output2))
- return "The 2 outputs have different lengths"
- . = ""
- for(var/i in 1 to output1.len)
- var/key1 = output1[i]
- var/key2 = output2[i]
- var/value1 = output1[key1]
- var/value2 = output2[key2]
- if(key1 != key2)
- . = "[.]\nkeys out of order: [i] ([key1]->[key2])"
- if(value1 != value2)
- . = "[.]\nvalues out of order: [i] ([value1]->[value2])"
- /proc/new_return_ordered_turfs(_x, _y, _z, _dir, obj/fake_port/port)
- var/cos = 1
- var/sin = 0
- switch(_dir)
- if(WEST)
- cos = 0
- sin = 1
- if(SOUTH)
- cos = -1
- sin = 0
- if(EAST)
- cos = 0
- sin = -1
- . = list()
- .["base"] = "[cos],[sin]"
- for(var/dx in 0 to port.width-1)
- var/compX = dx-port.dwidth
- for(var/dy in 0 to port.height-1)
- var/compY = dy-port.dheight
- // realX = _x + compX*cos - compY*sin
- // realY = _y + compY*cos + compX*sin
- // locate(realX, realY, _z)
- var/static/turf_num = 1
- .["turf#[turf_num++]"] = "[_x + compX*cos - compY*sin],[_y + compY*cos + compX*sin],[_z]"
- /proc/old_return_ordered_turfs(_x, _y, _z, _dir, obj/fake_port/port)
- if(!_dir)
- _dir = port.dir
- if(!_x)
- _x = port.x
- if(!_y)
- _y = port.y
- if(!_z)
- _z = port.z
- var/cos = 1
- var/sin = 0
- switch(_dir)
- if(WEST)
- cos = 0
- sin = 1
- if(SOUTH)
- cos = -1
- sin = 0
- if(EAST)
- cos = 0
- sin = -1
- . = list()
- .["base"] = "[cos],[sin]"
- var/xi
- var/yi
- for(var/dx=0, dx<port.width, ++dx)
- for(var/dy=0, dy<port.height, ++dy)
- xi = _x + (dx-port.dwidth)*cos - (dy-port.dheight)*sin
- yi = _y + (dy-port.dheight)*cos + (dx-port.dwidth)*sin
- var/static/turf_num = 1
- .["turf#[turf_num++]"] = "[xi],[yi],[_z]"
Add Comment
Please, Sign In to add comment