我修改了一些代码来测试我在python中设置交集的算法复杂度的假设:
s3,s4,s5,s6,t3,t4,t5,t6都被定义并且相当大 - 它们的交叉点也恰好相当大。
Variable
但以下声明'爆炸'..
$('#last_name').val($(this).val().split(" ")[1])
有什么想法吗?
我也会对任何想法让我的hacky代码变得不那么hacky感兴趣。
由于
答案 0 :(得分:2)
首先,您应该知道您看到的执行时间较慢是由于Protected Overrides Async Function SendAsync(request As HttpRequestMessage, cancellationToken As CancellationToken) As Task(Of HttpResponseMessage)
LogRequest(request) ' this is where the request is
' Create and process response
Dim response As HttpResponseMessage = Nothing
response = Await MyBase.SendAsync(request, cancellationToken)
LogResponse(response) ' here is the reponse
Return response
End Function
Private Function LogResponse(response As HttpResponseMessage) As Boolean
Try
Dim theJSON As String = Newtonsoft.Json.JsonConvert.SerializeObject(ExtractLoggingInfoFromResponse(response))
Catch ex As Exception
Return False
End Try
Return True
End Function
。算法本身非常快。
其次,您可以创建集合列表:
timeit
然后从该列表中删除该元素
s = [set(), set(), ...]
在你的情况下:
del s[i]
第三,对于较大的数据集,您可以使用NumPy来加速该过程:
import timeit
s = [set(), set(), set(), set()]
t = [set(), set(), set(), set()]
for x in xrange(int(1e3)):
s[0].add(x)
t[0].add(x*2 + x)
for x in xrange(int(1e4)):
s[1].add(x)
t[1].add(x*2 + x)
for x in xrange(int(1e5)):
s[2].add(x)
t[2].add(x*2 + x)
for x in xrange(int(1e6)):
s[3].add(x)
t[3].add(x*2 + x)
def _test():
for i, _ in enumerate(s):
for j, _ in enumerate(t):
if i >= j:
print i, j
print timeit.timeit('s[{0}].intersection(t[{1}])'.format(i, j), setup="from __main__ import s, t")
del s[i]